Skip to content

Backbone URI Storage is a Backbone.js Sync Adaptor designed for saving an application state model in the URI

License

Notifications You must be signed in to change notification settings

uzikilon/backbone-uriStorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Backbone URI Storage is a Backbone.js Sync Adaptor designed for saving an application state model in the URI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published