Backbone URI Storage is a Backbone.js Sync Adaptor designed for saving an application state model in the URI
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
Backbone.uriSync.history.js
Backbone.uriSync.js
LICENSE
README.md

README.md

Backbone URI Storage

Backbone URI Storage is a sync adaptor for Backbone.js, inspired by Backbone.localStorage.

As the name implies, it uses the URI for data storage engine, and therefore is ideal for implementing a model representing an application state or a state machine. The adapter saves the data in a JSON string, allowing the model to restore primitive variable types later.

An improved version of the adapter takes advantage of History.js for pushState support and cleaner URIs.

  • A working demo of the History.js driven adaptor can be found here.
  • Some background and what problem lead me to write this adaptor can be found here.

Usage:

var State = Backbone.Model.extend({
  sync: uriSync
});

var state = new State({id: 'state'});
// optional - bind to changes made on the URI and auto update the model
$(window).on("hashchange", function(){
  state.clear({silent: true});
  state.fetch();
});