https://github.com/cap32/subscribable-value
Subscribable value
https://github.com/cap32/subscribable-value
browser lightweight nodejs publish-subscribe state-management subscription tiny
Last synced: about 1 month ago
JSON representation
Subscribable value
- Host: GitHub
- URL: https://github.com/cap32/subscribable-value
- Owner: Cap32
- License: mit
- Created: 2016-10-25T10:40:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-08T09:24:01.000Z (over 8 years ago)
- Last Synced: 2025-10-13T15:35:25.023Z (8 months ago)
- Topics: browser, lightweight, nodejs, publish-subscribe, state-management, subscription, tiny
- Language: JavaScript
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Subscribable value
[](https://travis-ci.org/Cap32/subscribable-value) [](https://coveralls.io/github/Cap32/subscribable-value?branch=master) [](https://david-dm.org/Cap32/subscribable-value)
## Installing
Using npm:
```bash
$ npm install subscribable-value
```
Using yarn:
```bash
$ yarn add subscribable-value
```
## Usage
new SubValue(initialValue)
val.subscribe(handler)
val.set(anyValue)
val.get()
```js
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])
```js
const unsubscribe = val.subscribe((newValue) => {
console.log(newValue);
});
unsubscribe();
/* or `val.unsubscribe();` */
val.set(2333);
```
## License
MIT (c) Christopher Peng (Cap32)