Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{silent:true} in Backbone 1.0 version

I was updating my backbone version from 0.9.2 to 1.0 yet I've encountered a problem.

The model is not updating properly. It has delays in it. previously my code below works perfectly:

this.model({ attrib: true},{silent:true});

But after updating I removed the {silent:true} and everything works perfectly. The model updates properly.

I've read something like this on Backbonejs.org

Passing {silent:true} on change will no longer delay individual "change:attr" events, instead they are silenced entirely.

I dont get entirely what the statement means.

like image 975
n0minal Avatar asked Apr 17 '13 09:04

n0minal


1 Answers

About the meaning of the doc you quoted:

When you were doing (I guess the this.model was an error) this.set({attr: value}, {silent: true}), all the change events were just delayed until the next non-silent change. That is, if you were doing this.trigger('change') (as of the last versions of jQuery/Backbone, this.change() doesn't work anymore) or this.set('anotherAttr', anotherValue), a change:attr event would have been triggered.

As of Backbone 1.0, this behavior has changed. When you're using the silent flag, you're not delaying the change:attr event anymore, you're shutting it off completely.

So basically, to illustrate with a piece of code:

myModel.listenTo(myModel, 'change:attr', function() {alert();});
myModel.set('attr', true, {silent: true});
myModel.trigger('change');
// or myModel.set('anotherAttr', true);

will do an alert in Backbone prior 1.0, but not in Backbone 1.0.

like image 176
Loamhoof Avatar answered Oct 02 '22 19:10

Loamhoof