UNPKG

@platform/cell.tmpl

Version:

Template generator for the system

27 lines (22 loc) 595 B
import { takeUntil, filter } from 'rxjs/operators'; import { t, rx } from '../common'; /** * Event API. */ export function BusEvents(args: { bus: t.EventBus<any> }) { const { dispose, dispose$ } = rx.disposable(); const bus = rx.busAsType<t.NameEvent>(args.bus); const is = BusEvents.is; const $ = bus.$.pipe( takeUntil(dispose$), filter((e) => is.base(e)), ); return { $, is, dispose, dispose$ }; } /** * Event matching. */ const matcher = (startsWith: string) => (input: any) => rx.isEvent(input, { startsWith }); BusEvents.is = { base: matcher('namespace/'), };