backbone.storagesync
v2.0.1
Published
Backbone Sync to Web Storage.
Downloads
3
Readme
Backbone Storage Sync
Backbone Sync to Web Storage.
Getting Started
Replace the sync method on your model:
import storageSync from 'bacbone.storagesync';
const AwesomeModel = Backbone.Model.extend({
sync: storageSync()
...
})
Or with custom namespace:
const AwesomeModel = Backbone.Model.extend({
sync: storageSync('awesome')
...
})
Or with custom settings:
const AwesomeModel = Backbone.Model.extend({
sync: storageSync({
namespace: 'awesome',
storage: window.sessionStorage
})
...
})
And you're good to go!
Alternative Storage
By default storagesync will use globally localStorage
, however you may change it like so:
storageSync.storage = window.sessionStorage
Or if you want a fallback for when Web Storage isn't available:
storageSync.storage = new FakeStorage()
Note: this example uses my fake-storage library
Dependancies
Backbone, and Backbone.$.Deferred
must be present.
License
MIT - see LICENSE