Local Storage State Source

Provides a simple way of storing state in local storage.

var FooStorage = Marty.createStateSource({
  namespace: 'foos',
  type: 'localStorage',
  saveFoo: function (foo) {
    this.set('bar', foo);
  },
  getFoo: function (id) {
    return this.get(id);
  }
});
class FooStorage extends Marty.LocalStorageStateSource {
  constructor(options) {
    super(options);
    this.namespace = 'foos';
  }
  saveFoo(foo) {
    this.set('bar', foo);
  }
  getFoo(id) {
    return this.get(id);
  }
}

namespace

An (optional) prefix for keys.

get(key)

Gets the item in the storage with the given key. If the item exists, it will deserialize it.

set(key, obj)

Serializes the object to a JSON string before and then inserts into the storage with the given key.