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 as periodic, ksShare as share, ksFilter as filter, ksTake as take, Some, None } from "@keiii/k-stream";
const stream = periodic(100, share)
.pipe(filter(n => n % 2 === 0 ? Some(n) : None(n)))
.pipe(take(10));
stream.subscribe({
next: console.log,
complete: () => console.log("complete!"),
});
K-Steam provides helper function to create steam from your data source:
const stream = ksCreateStream<MouseEvent>(ksShare, ({ next, complete }) => {
const handler = (e: MouseEvent) => next(e);
document.addEventListener("click", handler);
return { unsubscribe: () => document.removeEventListener("click", handler) };
});
Goals
- “Hot” streams stay “hot” after pipe usage
- Do not lose type information
- RxJS similar
ToDo
- withLatestFrom
- audit
- repeat
- repeatWhen
- ...etc.