manage your backbone model/collection sync policy easily, with built-in support for localStorage/chrome.storage
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
docs
src
wrapper
.gitignore
.jshintrc
Gruntfile.coffee
LICENSE
README.md
package.json

README.md

backbone.storageEngine

manage your backbone model/collection sync policy easily, with built-in support for localStorage/chrome.storage

build commands

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

use localStorage / chrome.storage

    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

implement your own engine

    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'
    }

decide which engine to use on the fly

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
    }