From cdcb99a502b8643f113f0818f4979b34b3e8d5f7 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 9 Jun 2016 13:07:05 -0700 Subject: [PATCH] Improvements from PR feedback --- lib/browser/index.js | 25 ++++++++++--------------- src/js_realm.hpp | 1 - 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/browser/index.js b/lib/browser/index.js index b189a7e4..add249a2 100644 --- a/lib/browser/index.js +++ b/lib/browser/index.js @@ -56,6 +56,13 @@ function setupRealm(realm, realmId) { }); } +function getObjectType(realm, type) { + if (typeof type == 'function') { + return objects.typeForConstructor(realm[keys.realm], type); + } + return type; +} + export default class Realm { constructor(config) { let schemas = typeof config == 'object' && config.schema; @@ -90,30 +97,18 @@ export default class Realm { } create(type, ...args) { - if (typeof type == 'function') { - type = objects.typeForConstructor(this[keys.realm], type); - } - let method = util.createMethod(objectTypes.REALM, 'create', true); - return method.apply(this, [type, ...args]); + return method.apply(this, [getObjectType(this, type), ...args]); } objects(type, ...args) { - if (typeof type == 'function') { - type = objects.typeForConstructor(this[keys.realm], type); - } - let method = util.createMethod(objectTypes.REALM, 'objects'); - return method.apply(this, [type, ...args]); + return method.apply(this, [getObjectType(this, type), ...args]); } objectForPrimaryKey(type, ...args) { - if (typeof type == 'function') { - type = objects.typeForConstructor(this[keys.realm], type); - } - let method = util.createMethod(objectTypes.REALM, 'objectForPrimaryKey'); - return method.apply(this, [type, ...args]); + return method.apply(this, [getObjectType(this, type), ...args]); } } diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 271f7fa4..c5f13233 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -208,7 +208,6 @@ public: return name; } - // converts constructor object or type name to type name static const ObjectSchema& validated_object_schema_for_value(ContextType ctx, const SharedRealm &realm, const ValueType &value) { std::string object_type;