12

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.

Thaddeus Albers
  • 4,094
  • 5
  • 32
  • 42
n0minal
  • 3,195
  • 9
  • 46
  • 71
  • 1
    possible duplicate of [In Backbone.js, why do silent changes trigger change events eventually?](http://stackoverflow.com/questions/10030139/in-backbone-js-why-do-silent-changes-trigger-change-events-eventually) – WiredPrairie Apr 17 '13 at 10:56

1 Answers1

18

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.

Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
Loamhoof
  • 8,293
  • 27
  • 30
  • my apologies.. typo. :) just recently I read this. http://stackoverflow.com/questions/10030139/in-backbone-js-why-do-silent-changes-trigger-change-events-eventually and it seems to answer my question. Well also you're answer confirms it. thanks. – n0minal Apr 17 '13 at 09:28
  • @Dreyfus15 please consider accepting the answer or deleting your question, don't let it in this state while your problem seems solved. – Loamhoof Apr 17 '13 at 09:41
  • sorry. I forgot. I was going to mark your answer but it required me to mark your answer after 2hours and it slipped my mind. thanks – n0minal Apr 22 '13 at 13:34