-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement reset option for model.set #4101
base: master
Are you sure you want to change the base?
Conversation
This has been brought up and turned down a few times in the past. What's wrong with |
I'm on board with it, and it's been requested multiple times. We'll probably have a weird problem with |
AFAIK is the first PR, all other were issues. Clarification: it does not introduce a new method It does not change behavior of current code
In a model with attributes {a: 1, b: 2, c: 3}
|
Can you elaborate the problem? It does not change behavior of existing code. The change is restricted to set method and does not touch in fetch code at all. It will work for fetch also because the reset option is propagated to model.set that is only called inside fetch after a sucessfull request |
I like the Would just replacing the Edit: as a reference, see an implementation I'm using. |
How about using the name
|
1d573ae
to
2a33522
Compare
I think this PR is still valid. The suggested workaround And if this really is a duplicate of some other item, I think that other item should be referenced. |
2a33522
to
3a9621b
Compare
Implements the reset option for
model.set
. Fixes #3253 #4098When reset flag is passed as a truthy value to model.set, the properties that exist in model.attributes but not in the attributes being set will be deleted triggering the appropriate change event, effectively resetting the model state. If reset flag is passed to
model.fetch
and the request succeeds the model state will be reset with the values returned by the ajax call.This feature is necessary because the primitives provided by Backbone now does not allow to get such behavior without shortcomings.
model.clear().set(newattrs)
will fire change events twicemodel.clear({silent:true}).set(newattrs)
will not fire change event for the unset propertiesmodel.clear().fetch()
suffers from the above issues plus if request fails, will end with an empty modelAlso, in all the situations above, passing validate flag and validation failing, will end with an empty model
Important to note that the changes introduced by this PR are narrow and backward compatible.
Glad to iterate the changes if deems appropriate.