1.5.0 • Published 3 years ago

@jameslnewell/observable v1.5.0

Weekly downloads
25
License
MIT
Repository
github
Last release
3 years ago

@jameslnewell/observable

npm (scoped) Bundle Size Actions Status

A super simple and light-weight observable implementation.

Installation

yarn add @jameslnewell/observable

Usage

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

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago