fix for list notifications

This commit is contained in:
Ari Lazier 2016-08-03 09:03:14 -07:00
parent 9fd0adf147
commit 5916936db4
4 changed files with 47 additions and 5 deletions

View File

@ -5,12 +5,14 @@
}, },
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
"40F53A12E4AE40C654358321B91166ABD3E910A6" : 0, "40F53A12E4AE40C654358321B91166ABD3E910A6" : 0,
"F6F96CA34C5878B0A9123C7C37855491A5E599DA" : 0 "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : 0,
"8F3C415DA79CDA7D23734F285B95F9F9A3C0CB81" : 0
}, },
"DVTSourceControlWorkspaceBlueprintIdentifierKey" : "5EE721F9-041C-4877-9E73-A925C9DB080A", "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "5EE721F9-041C-4877-9E73-A925C9DB080A",
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
"40F53A12E4AE40C654358321B91166ABD3E910A6" : "realm-js\/", "40F53A12E4AE40C654358321B91166ABD3E910A6" : "realm-js\/",
"F6F96CA34C5878B0A9123C7C37855491A5E599DA" : "realm-js\/vendor\/GCDWebServer\/" "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : "realm-js\/vendor\/GCDWebServer\/",
"8F3C415DA79CDA7D23734F285B95F9F9A3C0CB81" : "realm-js\/src\/object-store\/"
}, },
"DVTSourceControlWorkspaceBlueprintNameKey" : "Realm", "DVTSourceControlWorkspaceBlueprintNameKey" : "Realm",
"DVTSourceControlWorkspaceBlueprintVersion" : 204, "DVTSourceControlWorkspaceBlueprintVersion" : 204,
@ -21,6 +23,11 @@
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "40F53A12E4AE40C654358321B91166ABD3E910A6" "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "40F53A12E4AE40C654358321B91166ABD3E910A6"
}, },
{
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/realm\/realm-object-store.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8F3C415DA79CDA7D23734F285B95F9F9A3C0CB81"
},
{ {
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/swisspol\/GCDWebServer.git", "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/swisspol\/GCDWebServer.git",
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git",

View File

@ -259,12 +259,13 @@ void ListClass<T>::add_listener(ContextType ctx, ObjectType this_object, size_t
Protected<ObjectType> protected_this(ctx, this_object); Protected<ObjectType> protected_this(ctx, this_object);
Protected<typename T::GlobalContext> protected_ctx(Context<T>::get_global_context(ctx)); Protected<typename T::GlobalContext> protected_ctx(Context<T>::get_global_context(ctx));
list->add_notification_callback([=](CollectionChangeSet change_set, std::exception_ptr exception) { auto token = list->add_notification_callback([=](CollectionChangeSet change_set, std::exception_ptr exception) {
ValueType arguments[2]; ValueType arguments[2];
arguments[0] = static_cast<ObjectType>(protected_this); arguments[0] = static_cast<ObjectType>(protected_this);
arguments[1] = Value::from_undefined(protected_ctx); arguments[1] = CollectionClass<T>::create_collection_change_set(protected_ctx, change_set);
Function<T>::call(protected_ctx, protected_callback, protected_this, 2, arguments); Function<T>::call(protected_ctx, protected_callback, protected_this, 2, arguments);
}); });
list->m_notification_tokens.emplace(protected_callback, std::move(token));
} }
template<typename T> template<typename T>

View File

@ -163,5 +163,34 @@ module.exports = {
[[], [], [0, 2]] [[], [], [0, 2]]
] ]
); );
} },
testListAddNotifications() {
let ListObject = {
name: 'ListObject',
primaryKey: 'id',
properties: {
id: 'int',
list: {type: 'list', objectType: 'TestObject'},
}
};
var config = { schema: [schemas.TestObject, ListObject] };
return createCollectionChangeTest(
config,
function(realm) {
let listObject;
realm.write(() => {
listObject = realm.create('ListObject', {id: 0, list: []})
});
return listObject.list;
},
[
[config, 'list_method', 'ListObject', 'list', 'push', {doubleCol: 0}, {doubleCol: 1}]
],
[
[[], [], []],
[[0, 1], [], []]
]
);
},
}; };

View File

@ -44,6 +44,11 @@ function handleMessage(message) {
else if (message[1] == 'update') { else if (message[1] == 'update') {
result = message[3].map((value) => realm.create(message[2], value, true)); result = message[3].map((value) => realm.create(message[2], value, true));
} }
else if (message[1] == 'list_method') {
var listObject = realm.objects(message[2])[0];
var list = listObject[message[3]];
result = list[message[4]].apply(list, message.slice(5));
}
else { else {
throw new Error('Unknown realm method: ' + message[1]); throw new Error('Unknown realm method: ' + message[1]);
} }