Comparing version 0.1.21 to 0.1.23
@@ -38,2 +38,3 @@ // Generated by CoffeeScript 1.6.2 | ||
this.linen = field.linen; | ||
this._callstack = flatstack(); | ||
this.transform().map(function(model) { | ||
@@ -62,2 +63,5 @@ model = _this._map(model); | ||
Collection.prototype._map = function(data) { | ||
if (!this.field.options.ref) { | ||
return data; | ||
} | ||
if (data != null ? data.__isModel : void 0) { | ||
@@ -79,2 +83,5 @@ return data; | ||
model = this._map(data); | ||
if (!this.field.options.ref) { | ||
return model; | ||
} | ||
model.collection = this; | ||
@@ -117,3 +124,3 @@ model.owner = this.owner; | ||
return model.once("remove", function(err) { | ||
return typeof model.once === "function" ? model.once("remove", function(err) { | ||
var i; | ||
@@ -127,3 +134,3 @@ | ||
return _this._ignorePersist = false; | ||
}); | ||
}) : void 0; | ||
}; | ||
@@ -161,9 +168,14 @@ | ||
} | ||
this.field.fetch(payload.collection(this).method("GET").data, function(err, models) { | ||
if (err != null) { | ||
return next(err); | ||
} | ||
if (models) { | ||
_this._reset(models); | ||
} | ||
this._callstack.push(function(next) { | ||
return _this.field.fetch(payload.collection(_this).method("GET").data, function(err, models) { | ||
if (err != null) { | ||
return next(err); | ||
} | ||
if (models) { | ||
_this._reset(models); | ||
} | ||
return next(); | ||
}); | ||
}); | ||
this._callstack.push(function() { | ||
return next(); | ||
@@ -207,5 +219,7 @@ }); | ||
newItem = src[i]; | ||
if (existingItem.get("_id") === newItem._id) { | ||
existingItem.set(newItem); | ||
src.splice(i, 1); | ||
if (this._compare(existingItem, newItem)) { | ||
if (this.field.options.ref) { | ||
existingItem.set(newItem); | ||
src.splice(i, 1); | ||
} | ||
break; | ||
@@ -220,3 +234,3 @@ } | ||
newItem = src2[_l]; | ||
if (existingItem.get("_id") === newItem._id) { | ||
if (this._compare(existingItem, newItem)) { | ||
found = true; | ||
@@ -227,3 +241,2 @@ break; | ||
if (!found) { | ||
console.log("RM"); | ||
this.splice(i, 1); | ||
@@ -243,2 +256,14 @@ } | ||
Collection.prototype._compare = function(a, b) { | ||
if (!this.field.options.ref) { | ||
return a === b; | ||
} else { | ||
return a.get("_id") === b._id; | ||
} | ||
}; | ||
/* | ||
*/ | ||
Collection.prototype.toJSON = function() { | ||
@@ -251,3 +276,3 @@ var model, models, _i, _len, _ref; | ||
model = _ref[_i]; | ||
models.push(model.push(model.__isModel ? model.toJSON() : model)); | ||
models.push(model.__isModel ? model.toJSON() : model); | ||
} | ||
@@ -262,6 +287,10 @@ return models; | ||
Collection.prototype._persistInsert = function(model) { | ||
var _this = this; | ||
if (this._ignorePersist || this.owner.isNew()) { | ||
return; | ||
} | ||
return this.field.fetch(payload.collection(this).target(model).method("POST").data, function() {}); | ||
return this._callstack.push(function(next) { | ||
return _this.field.fetch(payload.collection(_this).target(model).method("POST").data, next); | ||
}); | ||
}; | ||
@@ -274,2 +303,4 @@ | ||
Collection.prototype._persistRemove = function(model) { | ||
var _this = this; | ||
if (this._ignorePersist || this.owner.isNew()) { | ||
@@ -281,3 +312,5 @@ return; | ||
} | ||
return this.field.fetch(payload.collection(this).target(model).method("DELETE").data, function() {}); | ||
return this._callstack.push(function(next) { | ||
return _this.field.fetch(payload.collection(_this).target(model).method("DELETE").data, next); | ||
}); | ||
}; | ||
@@ -284,0 +317,0 @@ |
@@ -199,4 +199,4 @@ // Generated by CoffeeScript 1.6.2 | ||
Field.prototype.map = function(value) { | ||
var col, model; | ||
Field.prototype.map = function(model, value) { | ||
var col; | ||
@@ -206,11 +206,10 @@ if (this.options.multi && value.__isCollection) { | ||
} | ||
if (this.options.ref) { | ||
if (this.options.multi) { | ||
col = model.get(this.property) || new Collection(this); | ||
col._reset(value || []); | ||
return col; | ||
} else if (this.options.ref) { | ||
if (value.__isModel) { | ||
return value; | ||
} | ||
if (this.options.multi) { | ||
col = new Collection(this); | ||
col._reset(value || []); | ||
return col; | ||
} | ||
model = this.linen.model(this.options.ref, value); | ||
@@ -217,0 +216,0 @@ model.field = this; |
@@ -95,3 +95,3 @@ // Generated by CoffeeScript 1.6.2 | ||
Fields.prototype.map = function(key, value) { | ||
Fields.prototype.map = function(model, key, value) { | ||
var field; | ||
@@ -102,3 +102,3 @@ | ||
} | ||
return field.map(value); | ||
return field.map(model, value); | ||
}; | ||
@@ -105,0 +105,0 @@ |
@@ -78,3 +78,3 @@ // Generated by CoffeeScript 1.6.2 | ||
Model.prototype._set = function(key, value) { | ||
return Model.__super__._set.call(this, key, this.schema.map(key, value)); | ||
return Model.__super__._set.call(this, key, this.schema.map(this, key, value)); | ||
}; | ||
@@ -81,0 +81,0 @@ |
@@ -62,4 +62,4 @@ // Generated by CoffeeScript 1.6.2 | ||
Schema.prototype.map = function(key, value) { | ||
return this.fields.map(key, value); | ||
Schema.prototype.map = function(model, key, value) { | ||
return this.fields.map(model, key, value); | ||
}; | ||
@@ -66,0 +66,0 @@ |
{ | ||
"name": "linen", | ||
"version": "0.1.21", | ||
"version": "0.1.23", | ||
"description": "```javascript", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -35,4 +35,4 @@ var schemas = require("./helpers/schemas"), | ||
//until they're FULLY loaded. | ||
it("craig's friends collection is empty", function() { | ||
expect(items.craigsFriends.length()).to.be(0); | ||
it("craig's friends collection is not empty", function() { | ||
expect(items.craigsFriends.length()).to.be(5); | ||
}); | ||
@@ -43,4 +43,4 @@ | ||
items.craigsFriends.fetch(function() { | ||
items.craigsFriends.last().get("location").fetch(function() { | ||
expect(items.craigsFriends.last().get("location.name")).to.be("Palo Alto"); | ||
items.craigsFriends.first().get("location").fetch(function() { | ||
expect(items.craigsFriends.first().get("location.name")).to.be("Palo Alto"); | ||
next(); | ||
@@ -47,0 +47,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
73511
39
1718