https://github.com/jklepatch/observable-lite
A super simple implementation of the Observable pattern. Inspired by RxJS.
https://github.com/jklepatch/observable-lite
Last synced: 4 months ago
JSON representation
A super simple implementation of the Observable pattern. Inspired by RxJS.
- Host: GitHub
- URL: https://github.com/jklepatch/observable-lite
- Owner: jklepatch
- Created: 2019-06-09T16:32:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-09T17:28:40.000Z (over 6 years ago)
- Last Synced: 2025-06-10T15:50:24.397Z (8 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Observable lite
Super simple implementation of Observable in Nodejs. Inspired by RxJS.
## Getting started
Add this to your `package.json`:
```
...
"dependencies": {
observable-lite": "git+https://github.com/jklepatch/observable-lite.git",
...
},
...
```
Then run `npm install`
## Example
```
const Observable = require('observable-lite');
const observable = new Observable(subscriber => {
subscriber.next(1);
subscriber.next(2);
subscriber.next(3);
setTimeout(() => {
subscriber.next(4);
subscriber.complete();
}, 2000);
});
const subscription = observable.subscribe({
next(val) { console.log(val) },
complete() { console.log() }
});
setTimeout(() => subscription.unsubscribe(), 1000);
/**
* Will print:
* 1
* 2
* 3
*/
```
More examples in `examples` folder.