mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-10 23:48:12 -05:00
Merge pull request #4292 from Noodlex/fix_model_event_changeId
Trigger the "changeId" event only if prevId is different from this.id.
This commit is contained in:
@@ -523,7 +523,9 @@
|
||||
if (this.idAttribute in attrs) {
|
||||
var prevId = this.id;
|
||||
this.id = this.get(this.idAttribute);
|
||||
this.trigger('changeId', this, prevId, options);
|
||||
if (this.id !== prevId) {
|
||||
this.trigger('changeId', this, prevId, options);
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger all relevant attribute changes.
|
||||
|
||||
@@ -1476,4 +1476,15 @@
|
||||
assert.equal(model.id, 3);
|
||||
});
|
||||
|
||||
QUnit.test('#4289 - Trigger "changeId" need to be generate only if the content id change', function(assert) {
|
||||
assert.expect(1);
|
||||
var model = new Backbone.Model({id: 1});
|
||||
model.idAttribute = 'id';
|
||||
model.on('changeId', function(m) {
|
||||
assert.equal(m.get('id'), 2);
|
||||
});
|
||||
model.set({id: 1});
|
||||
model.set({id: 2});
|
||||
});
|
||||
|
||||
})(QUnit);
|
||||
|
||||
Reference in New Issue
Block a user