localStorage-ns
Namespaced key/value store backed by localStorage with events and default value loading.
Example:
let foo = let bar = foobar foo //=> 'Kevin'foo //=> '34' bar //=> 'Charlie'bar //=> '29'
API
Store(name, [defaults])
Create a new namespaced store with name
and optional defaults
.
store#set(key, value)
Set key
to value
.
store#get(key)
Return value of key
.
store#clear()
Clear the namespaced store.
store#on(event, fn)
Listen for the given event
and execute callback fn
. Available events are:
- set: Emitted whenever a
key
is being set. Both thekey
being set and thevalue
ofkey
will be passed to the callback. - change: Emitted on any change. No values are passed to the callback.
- clear: Emitted when the store is cleared. No values are passed to the callback.
License
MIT