UNPKG

@thi.ng/rstream

Version:

Reactive streams & subscription primitives for constructing dataflow graphs / pipelines

27 lines (26 loc) 659 B
import { View } from "@thi.ng/atom/view"; import { __optsWithID } from "./idgen.js"; import { Stream } from "./stream.js"; const fromViewUnsafe = (atom, opts) => fromView(atom, opts); function fromView(atom, opts) { opts = __optsWithID("view", opts); return new Stream((stream) => { let isActive = true; const tx = opts.tx; const view = new View( atom, opts.path, tx ? (x) => isActive && (x = tx(x), stream.next(x), x) : (x) => isActive && (stream.next(x), x), false, opts.equiv ); return () => { isActive = false; view.release(); }; }, opts); } export { fromView, fromViewUnsafe };