mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
18
backbone.js
18
backbone.js
@@ -1148,14 +1148,16 @@
|
||||
// events simply proxy through. "add" and "remove" events that originate
|
||||
// in other collections are ignored.
|
||||
_onModelEvent: function(event, model, collection, options) {
|
||||
if ((event === 'add' || event === 'remove') && collection !== this) return;
|
||||
if (event === 'destroy') this.remove(model, options);
|
||||
if (event === 'change') {
|
||||
var prevId = this.modelId(model.previousAttributes());
|
||||
var id = this.modelId(model.attributes);
|
||||
if (prevId !== id) {
|
||||
if (prevId != null) delete this._byId[prevId];
|
||||
if (id != null) this._byId[id] = model;
|
||||
if (model) {
|
||||
if ((event === 'add' || event === 'remove') && collection !== this) return;
|
||||
if (event === 'destroy') this.remove(model, options);
|
||||
if (event === 'change') {
|
||||
var prevId = this.modelId(model.previousAttributes());
|
||||
var id = this.modelId(model.attributes);
|
||||
if (prevId !== id) {
|
||||
if (prevId != null) delete this._byId[prevId];
|
||||
if (id != null) this._byId[id] = model;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.trigger.apply(this, arguments);
|
||||
|
||||
@@ -1803,4 +1803,14 @@
|
||||
collection.invoke('method', 1, 2, 3);
|
||||
});
|
||||
|
||||
QUnit.test('#3662 - triggering change without model will not error', function(assert) {
|
||||
assert.expect(1);
|
||||
var collection = new Backbone.Collection([{id: 1}]);
|
||||
var model = collection.first();
|
||||
collection.on('change', function(model) {
|
||||
assert.equal(model, undefined);
|
||||
});
|
||||
model.trigger('change');
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user