-
-
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
_removeModels regression bug #3693
Comments
We changed this in #3637. This is what you mean, right? var col = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}, {id: 4}]);
col.on('remove', function() {
col.get(3); // exists, but shouldn't.
});
col.remove(3); @jridgewell do we have a solution? I can't find the pull, but I think we changed the ordering of when |
We can just move the |
But then Alternatively, we could move the |
@akre54 yes, that's the use case. Unfortunately, the control flow is a little tricky. I would go with the one with the least side effects...regarding moving up the call and manually triggering, I'm not sure if there are cases where users or libraries might have registered something that will get cleared from the 'all' before triggering that would get skipped: Personally, I just would inline the cleanup code like before. Alternatively, you could update _removeReference to not unbind the model events and call |
Is there a reason you're trying to get the model in a
Agh, forgot about this. All of the above fixes would be acceptable to me. But I think the cleanup code should be left in |
@jridgewell a reason I've been doing it is that I'm binding to the collection like so:
In this way, I'm using the hooks to immutably update some other object. My handler is generic (i.e. doesn't use the parameters passed, instead just references the collection directly). It seems slightly misleading that inside the handler, this happens:
|
I have the same reason as @martynsmith - generic code for BackboneORM. Any update on a fix? |
My use case: During the collection's
In a more generic sense, it seems wrong that If the whole |
Fixes jashkenas#3693. This leaves open the question of whether events triggered on the model during a ‘remove’ listener should also trigger on the model. Just something to revisit for V2. ```js col.on('other', (model) => { // Should this be triggered? }); col.on('remove', (model) => { // If the model is really "removed" (we can't `#get` it anymore) // by the time this listener is called, then I'd argue that this // shouldn't trigger the 'other' event on the collection... model.trigger('other'); }); ```
Fixes jashkenas#3693. This leaves open the question of whether events triggered on the model during a ‘remove’ listener should also trigger on the model. Just something to revisit for V2. ```js col.on('other', (model) => { // Should this be triggered? }); col.on('remove', (model) => { // If the model is really "removed" (we can't `#get` it anymore) // by the time this listener is called, then I'd argue that this // shouldn't trigger the 'other' event on the collection... model.trigger('other'); }); ```
It looks like in 1.2.1, _removeModels was simplified, but introduced a regression bug.
Removed the following lines after
if (!model) continue;
What this means is that if you are listening to a remove event and you check for removal, you will get into an infinite loop because the event is now called before the id is removed from
this._byId
:I think the _byId code should be put back so when events are fired, they represent the most up-to-date state.
The text was updated successfully, but these errors were encountered: