From 5916936db4986ee384bddaaa2770dbb69fde410d Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 3 Aug 2016 09:03:14 -0700 Subject: [PATCH] fix for list notifications --- .../xcshareddata/Realm.xcscmblueprint | 11 +++++-- src/js_list.hpp | 5 +-- tests/js/async-tests.js | 31 ++++++++++++++++++- tests/js/worker-tests-script.js | 5 +++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Realm.xcworkspace/xcshareddata/Realm.xcscmblueprint b/Realm.xcworkspace/xcshareddata/Realm.xcscmblueprint index 3a7fb82e..ab8ab04a 100644 --- a/Realm.xcworkspace/xcshareddata/Realm.xcscmblueprint +++ b/Realm.xcworkspace/xcshareddata/Realm.xcscmblueprint @@ -5,12 +5,14 @@ }, "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { "40F53A12E4AE40C654358321B91166ABD3E910A6" : 0, - "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : 0 + "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : 0, + "8F3C415DA79CDA7D23734F285B95F9F9A3C0CB81" : 0 }, "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "5EE721F9-041C-4877-9E73-A925C9DB080A", "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { "40F53A12E4AE40C654358321B91166ABD3E910A6" : "realm-js\/", - "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : "realm-js\/vendor\/GCDWebServer\/" + "F6F96CA34C5878B0A9123C7C37855491A5E599DA" : "realm-js\/vendor\/GCDWebServer\/", + "8F3C415DA79CDA7D23734F285B95F9F9A3C0CB81" : "realm-js\/src\/object-store\/" }, "DVTSourceControlWorkspaceBlueprintNameKey" : "Realm", "DVTSourceControlWorkspaceBlueprintVersion" : 204, @@ -21,6 +23,11 @@ "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", "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", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", diff --git a/src/js_list.hpp b/src/js_list.hpp index e8d40432..0e916ac7 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -259,12 +259,13 @@ void ListClass::add_listener(ContextType ctx, ObjectType this_object, size_t Protected protected_this(ctx, this_object); Protected protected_ctx(Context::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]; arguments[0] = static_cast(protected_this); - arguments[1] = Value::from_undefined(protected_ctx); + arguments[1] = CollectionClass::create_collection_change_set(protected_ctx, change_set); Function::call(protected_ctx, protected_callback, protected_this, 2, arguments); }); + list->m_notification_tokens.emplace(protected_callback, std::move(token)); } template diff --git a/tests/js/async-tests.js b/tests/js/async-tests.js index 27521ca3..31fb0e53 100644 --- a/tests/js/async-tests.js +++ b/tests/js/async-tests.js @@ -163,5 +163,34 @@ module.exports = { [[], [], [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], [], []] + ] + ); + }, }; diff --git a/tests/js/worker-tests-script.js b/tests/js/worker-tests-script.js index 40f86b59..49766a4a 100644 --- a/tests/js/worker-tests-script.js +++ b/tests/js/worker-tests-script.js @@ -44,6 +44,11 @@ function handleMessage(message) { else if (message[1] == 'update') { 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 { throw new Error('Unknown realm method: ' + message[1]); }