Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 1.17 KB

README.md

File metadata and controls

26 lines (21 loc) · 1.17 KB

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();
});