initial work on getting subscriptions to work in RN debugger (#1902)

* Getting subscriptions to work in RN debugger
This commit is contained in:
Kenneth Geisshirt 2018-07-09 19:54:21 +02:00 committed by GitHub
parent d82c981386
commit 805f3d0804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -18,11 +18,11 @@
'use strict';
import { objectTypes } from './constants';
import { keys, objectTypes } from './constants';
import { getterForProperty, createMethods } from './util';
import { deserialize } from './rpc';
export default class Subscription {
}
Object.defineProperties(Subscription.prototype, {
@ -36,3 +36,13 @@ createMethods(Subscription.prototype, objectTypes.SUBSCRIPTION, [
'addListener',
'removeListener'
]);
export function createSubscription(realmId, info) {
let subscription = Object.create(Subscription.prototype);
subscription[keys.realm] = "(Subscription object)";
subscription[keys.id] = info.id;
subscription[keys.type] = objectTypes.SUBSCRIPTION;
return subscription;
};

View File

@ -45,6 +45,7 @@ static const char * const RealmObjectTypesResults = "results";
static const char * const RealmObjectTypesRealm = "realm";
static const char * const RealmObjectTypesUser = "user";
static const char * const RealmObjectTypesSession = "session";
static const char * const RealmObjectTypeSubscription = "subscription";
static const char * const RealmObjectTypesUndefined = "undefined";
json serialize_object_schema(const realm::ObjectSchema &object_schema) {
@ -569,6 +570,17 @@ json RPCServer::serialize_json_value(JSValueRef js_value) {
{"data", session_dict}
};
}
else if (jsc::Object::is_instance<js::SubscriptionClass<jsc::Types>>(m_context, js_object)) {
json subscription_dict {
{"state", serialize_json_value(jsc::Object::get_property(m_context, js_object, "state"))},
{"error", serialize_json_value(jsc::Object::get_property(m_context, js_object, "error"))}
};
return {
{"type", RealmObjectTypeSubscription},
{"id", store_object(js_object)},
{"data", subscription_dict}
};
}
else if (jsc::Value::is_array(m_context, js_object)) {
uint32_t length = jsc::Object::validated_get_length(m_context, js_object);
std::vector<json> array;