backbone-relations
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -65,3 +65,3 @@ // Generated by CoffeeScript 1.4.0 | ||
if (prev) { | ||
prev.off({ | ||
model.stopListening(prev, { | ||
'change:id': onChangeId, | ||
@@ -73,3 +73,3 @@ destroy: onDestroy | ||
if (next) { | ||
next.on({ | ||
model.listenTo(next, { | ||
'change:id': onChangeId, | ||
@@ -100,3 +100,3 @@ destroy: onDestroy | ||
(models.filters = {})[theirs] = model; | ||
ctor.cache().on("add change:" + theirs, function(other) { | ||
model.listenTo(ctor.cache(), "add change:" + theirs, function(other) { | ||
if (model.id && model.id == other.get(theirs)) { | ||
@@ -106,3 +106,3 @@ return models.add(other); | ||
}); | ||
models.on("change:" + theirs, function(other, val) { | ||
model.listenTo(models, "change:" + theirs, function(other, val) { | ||
if (!model.id == val) { | ||
@@ -119,3 +119,3 @@ return models.remove(other); | ||
hasManyVia = function(model, name, rel) { | ||
var attrs, ctor, mine, models, theirs, via, viaCtor, | ||
var attrs, ctor, mine, models, other, otherModel, theirs, via, viaCtor, _i, _len, _ref, _results, | ||
_this = this; | ||
@@ -137,30 +137,38 @@ ctor = getCtor(rel.hasMany); | ||
attrs = {}; | ||
viaCtor.cache().on("add change:" + mine + " change:" + theirs, function(other) { | ||
if (model.id && model.id == other.get(mine)) { | ||
return via.add(other); | ||
model.listenTo(viaCtor.cache(), 'add', function(other) { | ||
var otherModel; | ||
if (!(model.id && model.id == other.get(mine) && (otherModel = ctor.cache().get(other.get(theirs))))) { | ||
return; | ||
} | ||
return via.remove(other); | ||
via.add(other); | ||
return models.add(otherModel); | ||
}); | ||
via.on({ | ||
add: function(other) { | ||
if (other = ctor.cache().get(other.get(theirs))) { | ||
return models.add(other); | ||
} | ||
}, | ||
remove: function(other) { | ||
return models.remove(models.get(other.get(theirs))); | ||
} | ||
}); | ||
ctor.cache().on('add', function(other) { | ||
if (!((attrs[mine] = model.id) && (attrs[theirs] = other.id))) { | ||
model.listenTo(ctor.cache(), 'add', function(other) { | ||
var otherVia; | ||
if (!((attrs[mine] = model.id) && (attrs[theirs] = other.id) && (otherVia = via.get(viaCtor.prototype._generateId(attrs))))) { | ||
return; | ||
} | ||
if (via.get(viaCtor.prototype._generateId(attrs))) { | ||
return models.add(other); | ||
} | ||
via.add(otherVia); | ||
return models.add(other); | ||
}); | ||
model.listenTo(via, 'remove', function(other) { | ||
return models.remove(models.get(other.get(theirs))); | ||
}); | ||
model.listenTo(models, 'remove', function(other) { | ||
attrs[mine] = model.id; | ||
attrs[theirs] = other.id; | ||
return via.remove(via.get(viaCtor.prototype._generateId(attrs))); | ||
}); | ||
if (model.id) { | ||
return via.add(viaCtor.cache().filter(function(other) { | ||
return model.id == other.get(mine); | ||
})); | ||
_ref = viaCtor.cache().models; | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
other = _ref[_i]; | ||
if (!(model.id == other.get(mine) && (otherModel = ctor.cache().get(other.get(theirs))))) { | ||
continue; | ||
} | ||
via.add(other); | ||
_results.push(models.add(otherModel)); | ||
} | ||
return _results; | ||
} | ||
@@ -167,0 +175,0 @@ }; |
{ | ||
"name": "backbone-relations", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"author": "Casey Foster <casey@caseywebdev.com>", | ||
@@ -5,0 +5,0 @@ "licence": "MIT", |
10823
216