UNPKG

@platform/state

Version:

A small, simple, strongly typed, [rx/observable] state-machine.

18 lines (17 loc) 805 B
import { rx } from '@platform/util.value'; import { filter, map, share, takeUntil } from 'rxjs/operators'; export function create(args) { const $ = args.event$.pipe(takeUntil(args.until$)); const changed$ = $.pipe(filter((e) => e.type === 'TreeState/changed'), map((e) => e.payload), share()); const patched$ = $.pipe(filter((e) => e.type === 'TreeState/patched'), map((e) => e.payload), share()); const childAdded$ = $.pipe(filter((e) => e.type === 'TreeState/child/added'), map((e) => e.payload), share()); const childRemoved$ = $.pipe(filter((e) => e.type === 'TreeState/child/removed'), map((e) => e.payload), share()); return { $, changed$, patched$, childAdded$, childRemoved$, payload: (type) => rx.payload($, type), }; }