Support named partial sync subscriptions.
This commit is contained in:
parent
fd5d4fb5c0
commit
a7597eb577
|
@ -1067,12 +1067,20 @@ void RealmClass<T>::object_for_object_id(ContextType ctx, ObjectType this_object
|
||||||
#if REALM_ENABLE_SYNC
|
#if REALM_ENABLE_SYNC
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void RealmClass<T>::subscribe_to_objects(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
void RealmClass<T>::subscribe_to_objects(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue &return_value) {
|
||||||
args.validate_count(3);
|
args.validate_count(4);
|
||||||
|
|
||||||
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
SharedRealm realm = *get_internal<T, RealmClass<T>>(this_object);
|
||||||
std::string object_type = Value::validated_to_string(ctx, args[0]);
|
std::string object_type = Value::validated_to_string(ctx, args[0]);
|
||||||
std::string query = Value::validated_to_string(ctx, args[1]);
|
std::string query = Value::validated_to_string(ctx, args[1]);
|
||||||
auto callback = Value::validated_to_function(ctx, args[2]);
|
|
||||||
|
std::string key;
|
||||||
|
FunctionType callback;
|
||||||
|
if (Value::is_function(ctx, args[1])) {
|
||||||
|
callback = Value::validated_to_function(ctx, args[2]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
key = Value::validated_to_string(ctx, args[2]);
|
||||||
|
}
|
||||||
|
|
||||||
auto &schema = realm->schema();
|
auto &schema = realm->schema();
|
||||||
auto object_schema = schema.find(object_type);
|
auto object_schema = schema.find(object_type);
|
||||||
|
@ -1081,6 +1089,10 @@ void RealmClass<T>::subscribe_to_objects(ContextType ctx, ObjectType this_object
|
||||||
throw std::runtime_error("Object type '" + object_type + "' not found in schema.");
|
throw std::runtime_error("Object type '" + object_type + "' not found in schema.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key == nullptr) {
|
||||||
|
partial_sync::register_query(*realm, key, object_type, query);
|
||||||
|
}
|
||||||
|
else {
|
||||||
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));
|
||||||
Protected<FunctionType> protected_callback(ctx, callback);
|
Protected<FunctionType> protected_callback(ctx, callback);
|
||||||
|
@ -1107,6 +1119,7 @@ void RealmClass<T>::subscribe_to_objects(ContextType ctx, ObjectType this_object
|
||||||
};
|
};
|
||||||
|
|
||||||
partial_sync::register_query(realm, object_type, query, std::move(cb));
|
partial_sync::register_query(realm, object_type, query, std::move(cb));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue