Why does Model._validate accept an attrs param if it ignores it? #1053

Closed
khiltd opened this Issue Feb 27, 2012 · 1 comment

Comments

Projects
None yet
2 participants
@ghost

ghost commented Feb 27, 2012

The comments state that _validate should Run validation against a set of incoming attributes, returningtrueif all is well, yet the first thing it does is obliterate what it's been passed by extending attrs to include every single attribute in the model object:

https://github.com/documentcloud/backbone/blob/master/backbone.js#L491

I can't say whether this is a good thing or a bad thing, but it's not what I would expect to happen by looking at the method signature and documentation. Validating everything all the time regardless of whether or not it's been changed seems a bit wasteful, and it makes unit testing validations more difficult than they need to be because you can't simply have a spy assert that the success callback hasn't been called after setting an invalid value. With this approach, the success callback may actually be called dozens of times before the one bad attribute you actually wanted to validate bombs out.

jashkenas closed this in dca02ec Feb 27, 2012

Owner

jashkenas commented Feb 27, 2012

Thanks -- I've updated the comment. The change in validate() was made with 0.9 because most folks using validate wanted to have a stateless method that ensured that the model was in a valid state, given the upcoming snapshot of what the attributes would become as a whole.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment