mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-10 22:36:01 +00:00
Improvements from PR feedback
This commit is contained in:
parent
3c657c3bbf
commit
cdcb99a502
@ -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 {
|
export default class Realm {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
let schemas = typeof config == 'object' && config.schema;
|
let schemas = typeof config == 'object' && config.schema;
|
||||||
@ -90,30 +97,18 @@ export default class Realm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create(type, ...args) {
|
create(type, ...args) {
|
||||||
if (typeof type == 'function') {
|
|
||||||
type = objects.typeForConstructor(this[keys.realm], type);
|
|
||||||
}
|
|
||||||
|
|
||||||
let method = util.createMethod(objectTypes.REALM, 'create', true);
|
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) {
|
objects(type, ...args) {
|
||||||
if (typeof type == 'function') {
|
|
||||||
type = objects.typeForConstructor(this[keys.realm], type);
|
|
||||||
}
|
|
||||||
|
|
||||||
let method = util.createMethod(objectTypes.REALM, 'objects');
|
let method = util.createMethod(objectTypes.REALM, 'objects');
|
||||||
return method.apply(this, [type, ...args]);
|
return method.apply(this, [getObjectType(this, type), ...args]);
|
||||||
}
|
}
|
||||||
|
|
||||||
objectForPrimaryKey(type, ...args) {
|
objectForPrimaryKey(type, ...args) {
|
||||||
if (typeof type == 'function') {
|
|
||||||
type = objects.typeForConstructor(this[keys.realm], type);
|
|
||||||
}
|
|
||||||
|
|
||||||
let method = util.createMethod(objectTypes.REALM, 'objectForPrimaryKey');
|
let method = util.createMethod(objectTypes.REALM, 'objectForPrimaryKey');
|
||||||
return method.apply(this, [type, ...args]);
|
return method.apply(this, [getObjectType(this, type), ...args]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,6 @@ public:
|
|||||||
return name;
|
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) {
|
static const ObjectSchema& validated_object_schema_for_value(ContextType ctx, const SharedRealm &realm, const ValueType &value) {
|
||||||
std::string object_type;
|
std::string object_type;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user