Functional reactive stream library for TypeScript
K-Stream is yet another a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code.
npm i @keiii/k-stream
Usage
import { ksPeriodic, ksShare, ksFilterMap, ksTake, some, none } from "@keiii/k-stream";
const stream = ksPeriodic(100, ksShare)
.pipe(ksFilterMap(n => (n % 2 === 0 ? some(n) : none)))
.pipe(ksTake(10));
stream.subscribe({
next: console.log,
complete: () => console.log('complete!'),
});
Create steam from your data source:
const stream = ksShare<MouseEvent>(observer => {
const handler = (e: MouseEvent) => observer.next(e);
document.addEventListener('click', handler);
return { unsubscribe: () => document.removeEventListener('click', handler) };
});
Goals
ToDo
- withLatestFrom
- audit
- repeat
- repeatWhen
- ...etc.