jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.1k stars 5.39k forks source link

Don't propagate the internal "unset" option to user code #4154

Closed marcovc closed 7 years ago

marcovc commented 7 years ago
let m = new Backbone.Model({a:1});
m.on("change",(model,options)=>console.log(options))
m.unset(a)

This prints {unset: true}

I my opinion the "unset" option is an implementation detail that should not be passed to my handler.

Would it be possible to clear it before triggering the "change" event on the model "set" method?

(Maybe I could fix it in my code by overriding the set method, and clearing it myself, but I think this is actually a bug).

Thanks Marco

jaapz commented 7 years ago

Why would this be a bug? I think it's useful to know whether a change event was fired because an attribute was unset. The value changed to "nothing".

marcovc commented 7 years ago

I think for that you can query changedAttributes(). Moreover, knowing the name of the method that caused the event ("unset" in this case) would be an exception (Backbone does not provide this for any other event).

jashkenas commented 7 years ago

Options is where Backbone stashes information about the change, unset, silent, wait, patch, etc -- are all options passed along. I think it's fine to have that information there. It doesn't need to affect your handler.