Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jameslnewell/observable
A super simple and light-weight observable implementation.
https://github.com/jameslnewell/observable
map observable observer pipe subscription
Last synced: 20 days ago
JSON representation
A super simple and light-weight observable implementation.
- Host: GitHub
- URL: https://github.com/jameslnewell/observable
- Owner: jameslnewell
- Created: 2019-10-23T15:05:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T06:33:46.000Z (about 2 years ago)
- Last Synced: 2024-11-28T16:29:59.032Z (about 1 month ago)
- Topics: map, observable, observer, pipe, subscription
- Language: TypeScript
- Size: 483 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @jameslnewell/observable
![npm (scoped)](https://img.shields.io/npm/v/@jameslnewell/observable.svg)
[![Bundle Size](https://badgen.net/bundlephobia/minzip/@jameslnewell/observable)](https://bundlephobia.com/result?p=@jameslnewell/observable)
[![Actions Status](https://github.com/jameslnewell/observable/workflows/main/badge.svg)](https://github.com/jameslnewell/observable/actions)A super simple and light-weight observable implementation.
## Installation
```bash
yarn add @jameslnewell/observable
```## Usage
```js
const {create, map, pipe} from '@jameslnewell/observable';const numbers = (ms = 1000) => create(subscriber => {
let count = 0;
const handle = setInterval(() => subscriber.next(count++), ms);
return () => clearInterval(handle);
});const letters = pipe(map(number => String.fromCharCode(65 + number)))(numbers())
const subscription = letters.subscribe({
next: data => console.log(data),
error: error => console.error(error),
completed: () => console.log('completed')
});subscription.unsubscribe();
```
## API
### fromArray(array)
### fromError(array)
### create(factory): Observable
### map(fn)(observable): Observable
### delay(ms)(observable): Observable
### pipe(fn1, fn2, fn3)(Observable): Observable
### isObservable(value): boolean
### firstValueFrom(observable: Observable): Promise
### lastValueFrom(observable: Observable): Promise