From 18641994c709518791cadde70eeac6ac67ac0212 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 7 Oct 2015 18:09:00 -0600 Subject: [PATCH] transaction rpc methods, return size when creating results --- ReactNative/RealmRPC.mm | 21 ++++++++++++++++++++- RealmJS.xcodeproj/project.pbxproj | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ReactNative/RealmRPC.mm b/ReactNative/RealmRPC.mm index a60e98a9..ff752187 100644 --- a/ReactNative/RealmRPC.mm +++ b/ReactNative/RealmRPC.mm @@ -26,6 +26,9 @@ #include "RJSRealm.hpp" #include "RJSUtil.hpp" +#include "shared_realm.hpp" +#include "results.hpp" + using RPCObjectID = long; using RPCRequest = std::function; static std::map s_requests; @@ -48,6 +51,21 @@ static RPCObjectID s_id_counter = 0; s_objects[realmId] = RealmConstructor(s_context, NULL, 1, &value, NULL); return "{\"realmId\":" + std::to_string(realmId) + "}"; }; + s_requests["/begin_transaction"] = [=](NSDictionary *dict) { + RPCObjectID realmId = [dict[@"realmId"] longValue]; + RJSGetInternal(s_objects[realmId])->get()->begin_transaction(); + return "{}"; + }; + s_requests["/cancel_transaction"] = [=](NSDictionary *dict) { + RPCObjectID realmId = [dict[@"realmId"] longValue]; + RJSGetInternal(s_objects[realmId])->get()->cancel_transaction(); + return "{}"; + }; + s_requests["/commit_transaction"] = [=](NSDictionary *dict) { + RPCObjectID realmId = [dict[@"realmId"] longValue]; + RJSGetInternal(s_objects[realmId])->get()->commit_transaction(); + return "{}"; + }; s_requests["/create_object"] = [=](NSDictionary *dict) { RPCObjectID newOid = s_id_counter++; RPCObjectID realmId = [dict[@"realmId"] longValue]; @@ -107,7 +125,8 @@ static RPCObjectID s_id_counter = 0; JSValueRef results = RealmObjects(s_context, NULL, s_objects[realmId], argumentCount, arguments, &exception); JSValueProtect(s_context, results); s_objects[newOid] = (JSObjectRef)results; - return "{\"resultsId\":" + std::to_string(realmId) + "}"; + size_t size = RJSGetInternal((JSObjectRef)results)->size(); + return "{\"resultsId\":" + std::to_string(realmId) + ", \"size\":" + std::to_string(size) + "}"; }; s_requests["/get_results_size"] = [=](NSDictionary *dict) { RPCObjectID resultsId = [dict[@"resultsId"] longValue]; diff --git a/RealmJS.xcodeproj/project.pbxproj b/RealmJS.xcodeproj/project.pbxproj index 942ffeab..e0990e38 100644 --- a/RealmJS.xcodeproj/project.pbxproj +++ b/RealmJS.xcodeproj/project.pbxproj @@ -604,6 +604,11 @@ "$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/", ); IPHONEOS_DEPLOYMENT_TARGET = 8.0; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-isystem", + core/include, + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -624,6 +629,11 @@ "$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/", ); IPHONEOS_DEPLOYMENT_TARGET = 8.0; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-isystem", + core/include, + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -644,6 +654,11 @@ "$(SRCROOT)/examples/ReactExample/node_modules/react-native/React/", ); IPHONEOS_DEPLOYMENT_TARGET = 8.0; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-isystem", + core/include, + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES;