0.1.4 • Published 7 years ago

remob-kvstore v0.1.4

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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)
0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

1.0.0

7 years ago