Extending changeset with partial sync info. Updating object store

This commit is contained in:
Kenneth Geisshirt 2017-12-19 14:54:23 +01:00
parent 9505b750f9
commit 0e5741696c
3 changed files with 24 additions and 1 deletions

View File

@ -161,6 +161,15 @@ module.exports = function(realmConstructor) {
}); });
return promise; return promise;
}; };
// Keep these value in sync with subscription_state.hpp
realmConstructor.Sync.SubscriptionState = {
Undefined: -3, // Unknown which state Partial Sync is in.
NotSupported: - 2, // Partial Sync not supported.
Error: -1, // An error was detect in Partial Sync.
Uninitialized: 0, // The subscription was just created, but not handled by sync yet.
Initialized: 1, // The subscription has been initialized successfully and are syncing data to the dev
};
} }
// TODO: Remove this now useless object. // TODO: Remove this now useless object.

View File

@ -23,6 +23,9 @@
#include "js_observable.hpp" #include "js_observable.hpp"
#include "collection_notifications.hpp" #include "collection_notifications.hpp"
#if REALM_ENABLE_SYNC
#include "subscription_state.hpp"
#endif
namespace realm { namespace realm {
namespace js { namespace js {
@ -69,6 +72,17 @@ typename T::Value CollectionClass<T>::create_collection_change_set(ContextType c
} }
Object::set_property(ctx, object, "modifications", Object::create_array(ctx, modifications)); Object::set_property(ctx, object, "modifications", Object::create_array(ctx, modifications));
#if REALM_ENABLE_SYNC
// Partial sync brings a number of additional properties. They only make sense if partial sync is used
// but we don't have the information avaiable here.
ObjectType partial_sync = Object::create_empty(ctx);
Object::set_property(ctx, partial_sync, "error", Value::from_string(ctx, change_set.partial_sync_error_message));
Object::set_property(ctx, partial_sync, "old_state", Value::from_number(ctx, static_cast<double>(change_set.partial_sync_old_state)));
Object::set_property(ctx, partial_sync, "new_state", Value::from_number(ctx, static_cast<double>(change_set.partial_sync_new_state)));
Object::set_property(ctx, object, "partial_sync", partial_sync);
#endif
return object; return object;
} }

@ -1 +1 @@
Subproject commit d681b1fb8a8ca7a8db1ab1edc25771d984795ebe Subproject commit a7b05a07a860eb78b8c0e02a7d8e57c72d9bd7d8