@thi.ng/rstream
Lightweight reactive multi-tap streams and transducer based transformation
pipeline constructs, written in TypeScript.
About
This library provides & uses three key building blocks for reactive programming:
- Stream sources: event targets, iterables, timers, promises, watches, workers, CSP channels, custom...
- Subscriptions: chained stream processors, each subscribable itself
- Transducers: stream transformers, individually or as part of a single subscription, see @thi.ng/transducers.
Using these building blocks, a growing number of high-level operations are provided too:
- stream merging
- pubsub
- sidechain partitioning (emits chunks from source, controlled by sidechain stream)
- sidechain toggle (toggles source based on signals from sidechain)
Furthermore, the
@thi.ng/rstream-log
package provides an extensible multi-level, multi-target logging solution based
on this library.
TODO
Installation
yarn add @thi.ng/rstream
Usage examples
Basic usage patterns
import * as rs from "@thi.ng/rstream";
import * as tx from "@thi.ng/transducers";
FPS counter
const raf = rs.fromRAF();
raf.subscribe(
{
next(x) {
console.log(x.toFixed(1), "fps");
}
},
tx.comp(
tx.benchmark(),
tx.movingAverage(10),
tx.map(x => 1000 / x)
)
);
raf.subscribe(rs.trace());
setTimeout(()=> raf.done(), 10000);
Stream merging
new rs.StreamMerge([
rs.fromEvent(document, "mousemove"),
rs.fromEvent(document, "mousedown"),
rs.fromEvent(document, "mouseup"),
])
.subscribe(tx.map((e) => [e.type, [e.clientX, e.clientY]]))
.subscribe(rs.trace());
TODO more to come... see tests for now!
Authors
License
© 2017 - 2018 Karsten Schmidt // Apache Software License 2.0