subscribable-value
v1.0.0
Published
Subscribable value
Downloads
5
Maintainers
Readme
Subscribable value
Installing
Using npm:
$ npm install subscribable-value
Using yarn:
$ yarn add subscribable-value
Usage
new SubValue(initialValue)
val.subscribe(handler)
val.set(anyValue)
val.get()
import SubValue from 'subscribable-value';
const val = new SubValue(0);
val.subscribe((newValue) => {
console.log(newValue); /* 2333 */
});
val.set(2333);
val.get() /* 2333 */
val.unsubscribe([handler])
const unsubscribe = val.subscribe((newValue) => {
console.log(newValue);
});
unsubscribe();
/* or `val.unsubscribe();` */
val.set(2333);
License
MIT (c) Christopher Peng (Cap32)