knockout-sync
Advanced tools
Comparing version 0.1.8 to 0.1.9
{ | ||
"name": "knockout-sync", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "A small backend using knockout mapping to sync entities with a RESTful Backend", | ||
@@ -5,0 +5,0 @@ "main": "Gruntfile.js", |
@@ -185,5 +185,12 @@ define(['./Exception', './EntityModel', 'lodash', 'knockout', 'knockout-mapping'], function(Exception, EntityModel, _, ko, koMapping) { | ||
this.getEntityMeta = function(entityFQN) { | ||
if (!that.meta[entityFQN]) { | ||
throw new Error("There is no EntityMeta stored for FQN: '"+entityFQN+"'"); | ||
} | ||
return that.meta[entityFQN]; | ||
}; | ||
this.hasEntityMeta = function(entityFQN) { | ||
return !!that.meta[entityFQN]; | ||
}; | ||
/** | ||
@@ -198,4 +205,4 @@ * Calculates the "inner" mapping passed as second parameter of the constructor to the model | ||
_.each(entityMeta.properties, function(property) { | ||
if (property.type && that.meta[property.type]) { | ||
var propertyEntityMeta = that.meta[property.type]; | ||
if (property.type && that.hasEntityMeta(property.type)) { | ||
var propertyEntityMeta = that.getEntityMeta(property.type); | ||
@@ -208,4 +215,6 @@ mapping[property.name] = { | ||
var fqn = that.getEntityFQNFromData(propertyEntityMeta, options.data); | ||
if (options.data.$type) { | ||
var relatedEntity = that.find(propertyEntityMeta.fqn, options.data.$ref); | ||
var relatedEntity = that.find(fqn, options.data.$ref); | ||
@@ -228,3 +237,3 @@ if (relatedEntity) { | ||
} else { | ||
return that.findOrHydrate(propertyEntityMeta.fqn, options.data); | ||
return that.findOrHydrate(fqn, options.data); | ||
} | ||
@@ -239,2 +248,11 @@ } | ||
this.getEntityFQNFromData = function(entityMeta, data) { | ||
// always trust __class from backend | ||
if (data.__class) { | ||
return ko.unwrap(data.__class).replace(/\\/g, '.'); | ||
} else { | ||
return entityMeta.fqn; | ||
} | ||
}; | ||
this.onHydrate = function(listener) { | ||
@@ -241,0 +259,0 @@ that.hydrateListeners.push(listener); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49673
1427