mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 22:36:01 +00:00
pr fixes
This commit is contained in:
parent
6f41c3cf68
commit
a1c4cd5702
14
lib/realm.js
14
lib/realm.js
@ -8,7 +8,7 @@ const rpc = require('./rpc');
|
|||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
|
|
||||||
const {keys, propTypes, objectTypes} = constants;
|
const {keys, propTypes, objectTypes} = constants;
|
||||||
const notificationsKey = Symbol();
|
const listenersKey = Symbol();
|
||||||
const resultsKey = Symbol();
|
const resultsKey = Symbol();
|
||||||
|
|
||||||
// TODO: DATA
|
// TODO: DATA
|
||||||
@ -39,7 +39,7 @@ class Realm {
|
|||||||
this[keys.id] = realmId;
|
this[keys.id] = realmId;
|
||||||
this[keys.realm] = realmId;
|
this[keys.realm] = realmId;
|
||||||
this[keys.type] = objectTypes.REALM;
|
this[keys.type] = objectTypes.REALM;
|
||||||
this[notificationsKey] = [];
|
this[listenersKey] = [];
|
||||||
this[resultsKey] = [];
|
this[resultsKey] = [];
|
||||||
|
|
||||||
[
|
[
|
||||||
@ -57,7 +57,7 @@ class Realm {
|
|||||||
if (name != 'change') {
|
if (name != 'change') {
|
||||||
throw new Error("Only 'change' notification is supported.");
|
throw new Error("Only 'change' notification is supported.");
|
||||||
}
|
}
|
||||||
this[notificationsKey].push(callback);
|
this[listenersKey].push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,8 +69,8 @@ class Realm {
|
|||||||
throw new Error("Only 'change' notification is supported.");
|
throw new Error("Only 'change' notification is supported.");
|
||||||
}
|
}
|
||||||
var index = 0;
|
var index = 0;
|
||||||
while((index = this[notificationsKey].indexOf(callback, index)) != -1) {
|
while((index = this[listenersKey].indexOf(callback, index)) != -1) {
|
||||||
this[notificationsKey].splice(index, 1);
|
this[listenersKey].splice(index, 1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class Realm {
|
|||||||
if (name != undefined && name != 'change') {
|
if (name != undefined && name != 'change') {
|
||||||
throw new Error("Only 'change' notification is supported.");
|
throw new Error("Only 'change' notification is supported.");
|
||||||
}
|
}
|
||||||
this[notificationsKey] = [];
|
this[listenersKey] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
objects() {
|
objects() {
|
||||||
@ -114,7 +114,7 @@ class Realm {
|
|||||||
results[keys.resize]();
|
results[keys.resize]();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let callback of this[notificationsKey]) {
|
for (let callback of this[listenersKey]) {
|
||||||
callback(this, 'change');
|
callback(this, 'change');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,6 @@ public:
|
|||||||
WeakRealm m_realm;
|
WeakRealm m_realm;
|
||||||
|
|
||||||
void notify(const char *notification_name) {
|
void notify(const char *notification_name) {
|
||||||
for (auto callback : m_notifications) {
|
|
||||||
JSValueRef arguments[2];
|
JSValueRef arguments[2];
|
||||||
SharedRealm realm = m_realm.lock();
|
SharedRealm realm = m_realm.lock();
|
||||||
if (!realm) {
|
if (!realm) {
|
||||||
@ -96,6 +95,7 @@ public:
|
|||||||
arguments[0] = realm_object;
|
arguments[0] = realm_object;
|
||||||
arguments[1] = RJSValueForString(m_context, notification_name);
|
arguments[1] = RJSValueForString(m_context, notification_name);
|
||||||
|
|
||||||
|
for (auto callback : m_notifications) {
|
||||||
JSValueRef ex = NULL;
|
JSValueRef ex = NULL;
|
||||||
JSObjectCallAsFunction(m_context, callback, realm_object, 2, arguments, &ex);
|
JSObjectCallAsFunction(m_context, callback, realm_object, 2, arguments, &ex);
|
||||||
if (ex) {
|
if (ex) {
|
||||||
@ -486,8 +486,6 @@ JSValueRef RealmRemoveAllListeners(JSContextRef ctx, JSObjectRef function, JSObj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JSValueRef RealmClose(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
JSValueRef RealmClose(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* jsException) {
|
||||||
try {
|
try {
|
||||||
RJSValidateArgumentCount(argumentCount, 0);
|
RJSValidateArgumentCount(argumentCount, 0);
|
||||||
@ -521,5 +519,3 @@ JSClassRef RJSRealmClass() {
|
|||||||
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, RJSRealmFuncs);
|
static JSClassRef s_realmClass = RJSCreateWrapperClass<SharedRealm *>("Realm", RealmGetProperty, NULL, RJSRealmFuncs);
|
||||||
return s_realmClass;
|
return s_realmClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -311,5 +311,17 @@ module.exports = BaseTest.extend({
|
|||||||
realm.write(function() {});
|
realm.write(function() {});
|
||||||
TestCase.assertEqual(notificationCount, 3);
|
TestCase.assertEqual(notificationCount, 3);
|
||||||
TestCase.assertEqual(secondNotificationCount, 1);
|
TestCase.assertEqual(secondNotificationCount, 1);
|
||||||
|
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
realm.addListener('invalid', function() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
realm.addListener('change', function() {
|
||||||
|
throw new Error('error');
|
||||||
|
});
|
||||||
|
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
realm.write(function() {});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user