documentcloud/backbone — pull request #1776 by albertsun (2012-10-26 14:39:10+00:00)
Title: Separate silent and wait options for set

The way the {silent:true} option works when setting model attributes seems very counter intuitive to me.

Looking at this test case.

```javascript
m = new Backbone.Model({"a":1,"b":2});
m.on("change", function() { console.log("change"); });
m.on("change:a", function() { console.log("change:a"); });
m.on("change:b", function() { console.log("change:b"); });
m.set({"b":22},{silent:true});
m.set({"a":11});
```

The output is

change:b
change:a
change
When I would expect to see only

change:a
change

It seems from 69b80f5e3a86452c4150caa249332f9ea4efd901 and https://github.com/documentcloud/backbone/issues/959#issuecomment-3833790 that this was a conscious decision about the way that silent should behave but it still seems odd to me.

It works fine for the case of doing a whole bunch of changes to a model in sequence and then triggering the change events all together at the end. But if the silent changes and the later non-silent change are happening at different times, then all of a sudden it looks like changing "a" will fire "change:a" and "change:b" when all the effects of setting "b" earlier should have already happened.

What I'm proposing is that set have two separate options, "silent" and "wait". "wait" will fire change:attr events like "silent" currently does, and the same way as passing "wait":true to save does. Passing "silent":true will not fire change:attr events.

This breaks backwards compatibility, but I think it makes set behave much more intuitively. You can either set attributes and tell the model to wait before firing change events, or set attributes and tell the model to never fire change events.