Store JSON data using multiple storage backends
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib Adding rescue blocks for get and clear Apr 22, 2013
test
.bowerrc
.gitignore
.travis.yml
LICENSE.md
README.md
bower.json
karma.conf.js
package.json

README.md

No Maintenance Intended Build Status

flight-storage

A Flight component for storing JSON data in arbitrary data stores. Currently supports:

  • Cookie
  • Data attributes
  • In-memory object
  • Local storage
  • Location hash
  • Window name

Installation

bower install --save flight-storage

Example

define(['flight-storage/manager'], function(StorageManager) {

  // Setup the store
  StorageManager.attachTo(document, {
    adapter: 'local-storage',
    saveEvent: 'storage-save',
    getEvent: 'storage-get',
    clearEvent: 'storage-clear'
  });

  // Listen for successful actions
  $(document).on('storage-save-success storage-get-success storage-clear-success', function(e, data) {
    console.log(e, data);
  });

  // Listen for errors
  $(document).on('storage-save-failure storage-get-failure storage-clear-failure', function(e, data) {
    console.error(e, data);
  });

  // Save a key/value pair
  $(document).trigger('storage-save', {key:'foo', value:{bar:'baz', boo:1337}});

  // Retrieve a key/value pair
  $(document).trigger('storage-get', {key:'foo'});

  // Clear the data store
  $(document).trigger('storage-clear');
});

or use the storage adapter mixins directly in your components

define(['flight/lib/component', 'flight-storage/adapters/local-storage'], function(defineComponent, withLocalStorage) {

  var MyComponent = defineComponent(myComponent, withLocalStorage);

  function myComponent() {

    this.after('initialize', function() {

      this.on('myComponentEvent', function(e, data) {
        // Save into local storage
        this.set(data.key, data.value);
      });

    });

  }

  return MyComponent;
});

Development

Development of this component needs Bower, and ideally Karma to be globally installed:

npm install -g bower karma

Then install the Node.js and client-side dependencies by running the following commands in the repo's root directory.

npm install
bower install

To continuously run the tests in Chrome and Firefox during development, just run:

karma start