-
-
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
Remove triggering Destroy: triggers Remove. Bug causes second Remove to remove the wrong thing. #3923
Comments
We usually say that passing
Can you explain this more? Our preferred way is for you to call |
This isn't an issue with silent true. This is an issue with the cleanup of the I have an existing project that sometimes, after hearing a For your curiosity, a little bit of extra information about my project: My project extends backbone to provide some asynchronous control flow. Sometimes it uses |
For what it's worth, this test:
Fails on the |
Right, again why are you calling We don't actually remove the reference until after the |
@ivarni Thanks! If a new version rolled out without this problem sometime soon, that would be fantastic. There's some complicated business logic; database sync assurance, abstractions to support moving away from strict REST if necessary, and other collections which should be tied to the state of the collection in question. That kind of thing. It is necessary to be able to call |
Dupe of #3693? If so, this'll be fixed in |
Possibly? I don't know. When is On line 1146, a non-optimistic if (event === 'destroy' && this.indexOf(model) > -1) this.remove(model, options);; Update:@jridgewell On a more careful look (I've visited this issue before, as it happens), #3693 appears to me to be related, and fixing its underlying issue will likely fix this. ivarni pointed out a test for this is passing on master. So while I hope that this issue has been fixed by the work on 3693, it's important to me to have an estimate for when the next release will occur, to gauge whether a work-around will be necessary. |
Fixed in version 1.3.1 and 1.3.3. Thanks! |
See comment below, this bug can be recreated without using
{silent: true}
at all.fiddle without
{silent: true}
original fiddle with
{silent: true}
I recently upgraded from Backbone 1.1.2 to Backbone 1.2.3. With my project as it is, when I remove a single item from a collection, that item and the last item (erroneously) in the collection are removed. The reason for this has to do with two things:
remove
is typically mapped todestroy
. The reasoning is that we don't want uncollected detritus floating about in case someone accidentally usesremove
on the collection.destroy
no longer behaves as it did before as regards thesilent: true
option.Destroy triggers a remove event that can no longer be silenced, which is conceptually fine as we have indeed already removed the model from the collection. However as occurs in #3847 ,
collection.get(model)
succeeds wherecollection.indexOf(model)
returns-1
. The logic leading to the faulty removal occurs at line 1103, and just below line 1106 contains a splice that given-1
as an index removes the last element in the collection.this.get(model)
, which is tested to prevent attempts to remove already removed items, delegates to_byId
which does not contain the model itself as a key, but does contain the model's id and cid when it shouldn't.Any one of the following changes will fix this bug:
destroy
changed to not trigger a'remove'
event when given the{ silent: true }
option_removeModels
modified to not splice out the last list element whenindexOf(model) == -1
_byId
before second remove call occursPlease let me know if there is a simple fix for my code which maintains the functionality of destroying an object when a remove event occurs.
The following code will reproduce this bug (or just use the fiddle):
The text was updated successfully, but these errors were encountered: