Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

fix remove handler to also delete references to existing models #207

Merged

Conversation

twalker
Copy link
Contributor

@twalker twalker commented May 31, 2013

The backgrid-select-all extension was removing references to unsaved models but not saved models. This fixes the issue by checking for model.id instead of just model.cid:

  this.listenTo(collection, "remove", function (model) {
    delete selectedModels[model.id || model.cid];
  });

@wyuenho
Copy link
Contributor

wyuenho commented Jun 1, 2013

Saved model also have cids no?

@twalker
Copy link
Contributor Author

twalker commented Jun 1, 2013

Interesting. Yes, saved models do have a cid.
But shouldn't the "true id" from the server take precedence over the automatically client assigned temporary id?

I would need to verify to be certain, but I suspect that I was seeing a mis-association between cid and id. Probably due to destroy calls followed by auto-assignement of different cid's. Giving model.id precedence kept the selectedModels from having an undefined value for a cid key.

Would you like further verification?

@wyuenho
Copy link
Contributor

wyuenho commented Jun 1, 2013

For backgrid's purposes, the select-all extension only needs 1 candidate key to keep track of which models within the collection were selected. cids are globally unique within a browser page so that would be sufficient. I'm not entirely sure what problem this PR is suppose to fix. Perhaps you could file a separate ticket illustrating your problem?

@wyuenho wyuenho closed this Jun 1, 2013
@twalker
Copy link
Contributor Author

twalker commented Jun 1, 2013

Sorry I'm not explaining the issue clearly. I think taking a look at the surrounding code will do a better job.
selectedModels is adding model references by the id for existing models:

https://github.com/wyuenho/backgrid/blob/master/src/extensions/select-all/backgrid-select-all.js#L150

Yet the remove handler is trying to delete by cid

https://github.com/wyuenho/backgrid/blob/master/src/extensions/select-all/backgrid-select-all.js#L158

There's a key mismatch. Which resulted in selectedModels having references to removed models--undefined.

The PR fixes the problem by using the same approach to removing a selectedModel as it does for adding a model.

@wyuenho wyuenho reopened this Jun 1, 2013
wyuenho added a commit that referenced this pull request Jun 1, 2013
Fix bug where the remove handler isn't deleting references to existing models
@wyuenho wyuenho merged commit 0b19f4a into cloudflarearchive:master Jun 1, 2013
@wyuenho
Copy link
Contributor

wyuenho commented Jun 1, 2013

Ah Ok thanks. Good catch.

@twalker twalker deleted the delete-selected-on-remove branch June 1, 2013 18:10
@wyuenho wyuenho mentioned this pull request Jun 5, 2013
wyuenho added a commit to cloudflarearchive/backgrid-select-all that referenced this pull request Aug 14, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants