https://github.com/mjancarik/esmj-observable
Tiny observable library for other extensibility
https://github.com/mjancarik/esmj-observable
Last synced: about 2 months ago
JSON representation
Tiny observable library for other extensibility
- Host: GitHub
- URL: https://github.com/mjancarik/esmj-observable
- Owner: mjancarik
- License: mit
- Created: 2022-12-03T22:07:20.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-22T21:33:52.000Z (11 months ago)
- Last Synced: 2025-08-08T16:00:03.667Z (2 months ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Observable
The `@esmj/observable` is tiny observable library for other extensibility.
## Requirements
- Node 18+
## Install
```shell
npm install @esmj/observable
```## Usage
It works for both Javascript modules (ESM and CJS).
```javascript
import { Observable, IObservable, IObserver } from '@esmj/observable';const observer: IObserver = {
next(value) {
console.log(value);
}
}const observable: IObservable = new Observable();
const { unsubscribe } = observable.subscribe(observer);
observable.next('Hello world'); // log: Hello world
unsubscribe();
```
## API
### observable = new Observable()
Create a new instance of Observable.#### pipe(...rest: ((observable) => observable)[])
Extends default observable logic.#### next(...rest: any[])
Monitoring start measure node metric.#### complete(...rest: any[])
Monitoring stop measure node metric.#### error(...rest: any[])
Monitoring start measure node metric.#### subscribe(observer)
Subscribe observer.Returns an subscription object with unsubscribe method.
##### observer
Type: `() => void | { next: () => void, error?: () => void, complete?: () => void}`#### unsubscribe(observer)
Remove observer.##### observer
Type: `() => void | { ?next: () => void, error?: () => void, complete?: () => void}`