jashkenas / jashkenas/backbone
Rethink Backbone.sync
- Dominant language
- JavaScript
- Stars
- 28.1k
- Forks
- 5.3k
- PR merge metrics
- No merged PRs in 30d
Description
As we all know, there are numerous plugins in the wild which override `Backbone.sync` with specific domain logic. Things like storage proxies, web socket connections, etc. The way plugins add this functionality tends to be messy and conflict with one another.
For Backbone v2 I suggest we reimplement how a custom sync should be added to Backbone. I've long suggested these plugins export a `CustomCollection` and `CustomModel` with a custom `sync` function implemented there, as opposed to globally overriding BB.sync; however they both have some merit. I would suggest something like the following adding a custom sync
``` js
function predicate(model, options) {
return model.useProxy;
}
function syncFn(model, options) {
// sync function as normal
}
// Whether this sync method should stop other syncs from being checked.
// This could be useful for storage syncs which wish to add data to an indexedDb
// while also executing an http sync
var exclusiveSync = false;
Backbone.addSyncMethod(predicate, syncfn, exclusiveSync);
```
Contributor guide
Research direction
Start by reading the current Backbone.sync entry point and reviewing how plugins override it. Compare the proposed predicate, sync function, and exclusiveSync behavior with the existing extension approach. Done means a settled custom-sync design with clear interaction and compatibility expectations, but the issue does not identify specific files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100