jashkenas / jashkenas/backbone
Should Backbone.Collection throw an error when client code attempts to add the same model twice?
- Dominant language
- JavaScript
- Stars
- 28.1k
- Forks
- 5.3k
- PR merge metrics
- No merged PRs in 30d
Description
While studying #4249, I found this old comment to another ticket by @jashkenas, in which he writes that Backbone once used to throw an error in this scenario: https://github.com/jashkenas/backbone/issues/2976#issuecomment-33711327.
> > If it were up to me, I would prefer that adding duplicate models would throw an error, though I imagine this would be a breaking change for many users.
>
> That's how it used to be ... and this behavior was an "enhancement" ;)
It is ambiguous from this comment alone whether the *throwing* was an "enhancement", or the *removal* of the throwing. It would not be the first time that a feature is inadvertently removed. If `aCollection.add([{id: 1}, {id: 1}])` was supposed to throw (which intuitively makes sense) and this was removed for no good reason, then I suggest reinstating this behavior in the future Backbone 2.0. First, though, we should investigate what happened exactly and why.
Contributor guide
Research direction
Start by tracing Backbone.Collection.add and reviewing the history behind the behavior, along with the linked #2976 discussion and comment. Done means establishing whether duplicate additions previously threw, why that behavior changed, and recording a clear recommendation for future Backbone 2.0 work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100