Skip to content
flux logoFluxReactive
Reusable push streams with subscription-owned cancellation, bounded buffering, and optional ecosystem adapters.
Version
v2.2.0
Size
3.0 KB gzip
Dependencies
Zero dependencies
BrowserNode ≥22SSRDeno
streampipeoffromfromEvent View all 25 exports

Why Flux?

Use Flux when an API pushes many values over time and consumers need independent cancellation. Streams describe reusable work; subscriptions own cleanup. Explicit queue capacity keeps async iteration from silently growing memory.

ts
// Before
const controller = new AbortController();
const render = (value: string) => console.log(value);
const handler = (event: Event) => render((event.target as HTMLInputElement).value);
input.addEventListener('input', handler);
setTimeout(() => controller.abort(), 5_000);

// After
import { fromEvent, map, pipe, takeUntil } from '@vielzeug/flux';

const updates = pipe(
  fromEvent<InputEvent>(input, 'input'),
  map((event) => (event.target as HTMLInputElement).value),
  takeUntil(controller.signal),
);

updates.subscribe({ error: console.error, next: render });
FeatureFluxRxJSTC39 Observable
Bundle size3.0 KBVaries by imported operatorsNative proposal / polyfill
Runtime dependencies
Subscription-owned cancellation
Explicit async queue policyOperator-dependentNo standard policy
Vielzeug adaptersRipple, Courier, Herald, PulseManual adaptersManual adapters

Use Flux when you need a small TypeScript stream primitive, explicit cancellation, and first-party Vielzeug adapters.

Consider RxJS when you need its larger operator catalog or third-party Observable integrations.

Installation

sh
pnpm add @vielzeug/flux
sh
npm install @vielzeug/flux
sh
yarn add @vielzeug/flux

Quick Start

ts
import { toArray, interval, map, pipe, take } from '@vielzeug/flux';

const firstThree = pipe(
  interval({ every: 100 }),
  map((value) => value * 2),
  take(3),
);

try {
  console.log(await toArray(firstThree, { maxItems: 3 })); // [0, 2, 4]
} catch (reason) {
  console.error('Stream failed', reason);
}

Features

  • stream() — define cold reusable work with one teardown function
  • pipe() — compose any number of typed operators
  • Subscription — own cancellation through unsubscribe() or AbortSignal
  • createChannel() — mutable multicast state with bounded replay
  • toAsyncIterable() — explicit capacity and overflow policy for pull consumers
  • retry() — retry failures with optional backoff
  • fromSignal() / toSignal() — bridge Ripple signals
  • fromQuery() — adapt Courier query state

Documentation

See Also

  • Ripple — adapt reactive signal state through @vielzeug/flux/ripple.
  • Courier — adapt query snapshots and SSE events through @vielzeug/flux/courier.
  • Herald — adapt typed bus events through @vielzeug/flux/herald.
  • Pulse — adapt connection and presence events through @vielzeug/flux/pulse.