0.1.4 • Published 7 years ago
remob-kvstore v0.1.4
remob-kvstore
Installation
npm install --save remob-kvstore
Usage
$ node
> const store = require("remob-kvstore")
> let unsubscribe = store.subscribe( (oldVal, newVal, id) => { console.log(oldVal, newVal, id); } );
> store.set("a", 1)
undefined 1 'a'
> store.get("a")
1
> store.set("a", 10)
1 10 'a'
> store.get("a")
10
> unsubscribe()
> store.set("a", 100)
> store.get("a")
100
API
get(id)
Get the value associated with id
set(id, val)
Associate val with id
subscribe(listener, id)
Listen on set
operation. id
is optional, when set, listen on that specific id's set
,
otherwise listen on all ids'.
listener accepts 3 arguments: oldVal
, newVal
, id
.
clearStore
Remove all values in store.
clearListeners
Remove all listeners.
clear
Remove all values in store. Then remove all listeners.
getValueRef
let ref = getValueRef();
console.log(ref.id)
ref.get() // --> get(ref.id)
reg.set(val) // --> set(ref.id, val)