documentcloud/backbone — Issue #757: model fires change event even though nothing has changed
Author: inapt
Created: 2011-11-23 16:22:57+00:00
State: open

It looks like there is a bug in the backbone model that might have been introduced when the following issue was resolved: https://github.com/documentcloud/backbone/issues/105.

Use-Case scenario: We create an apple object and during initialization we set a “state” attribute to 0, silently. We then call set() on that object again and pass in the same args (state of zero). At this point a change event should not be fired.

Code:

```javascript
// Fruit Model
Fruit = Backbone.Model.extend({
initialize: function(){
this.set({state: 0}, {silent: true});
}
})

// create new fruit object
var apple = new Fruit();
// "change" event has not been triggered: however, this._changed = true

// set state to 0
apple.set({state: 0});

// nothing has changed, but because this is not silent and this._changed has been previously
// set to true, we fire a change event... as seen in line 223

if (!alreadyChanging && !options.silent && this._changed) this.change(options);
```