manage your backbone model/collection sync policy easily, with built-in support for localStorage/chrome.storage
- Annotated Source
- Default Build with localStorage support ( minified )
- Full Build with localStorage AND chromestorage ( minified )
- more builds(amd wrapper / latebind) can be built easily
default build command
npm i grunt-cli -g
npm i
roll you own build
grunt clean dist:<pkg>:<wrapper> uglify
<pkg> might be core / default / full, or localstorage / chromestorage.
look Gruntfile.coffee for details
<wrapper> might be plain / amd / amd-lodash
look wrapper directory for details or simply roll your own wrapper
LocalModel = Backbone.Model.extend {
sync: Backbone.StorageEngine.Engine.LocalStorage.createSync model.name
}
ChromeCollection = Backbone.Collection.extend {
sync: Backbone.StorageEngine.Engine.ChromeStorage.createSync model.collection.name
}localStorage powered by jeromegn/Backbone.localStorage, and chrome.storage powered by scryptmouse/Backbone.ChromeStorage
MyEngine = Backbone.StorageEngine.Engine.Base.extend {
constructor: (@name)-> @
create: (model, options)->
read: (model, options)->
update: (model, options)->
delete: (model, options)->
}, {
construct: _.memoize (name)->
new this name
}
MyCollection = Backbone.Collection.extend {
sync: MyEngine.createSync 'my'
}requires Backbone.StorageEngine.Router.LateBind
BaseModel = Backbone.Model.extend {
sync: Backbone.StorageEngine.Router.LateBind.createSync (method, model, options)->
if model.type is 'local'
Backbone.StorageEngine.Engine.LocalStorage.construct model.name
else
MyEngine.construct model.name
}