import { importProxy } from "./importProxy"; import type { UnpackEvt, Evt, CtxLike, NonPostableEvtLike } from "./types"; export function mergeImpl>( ctx: CtxLike | undefined, evts: readonly EvtUnion[] ): Evt> { const evtUnion = new importProxy.Evt>(); const callback = (data: UnpackEvt) => evtUnion.post(data) evts.forEach( evt => { if (ctx === undefined) { evt.attach(callback); } else { evt.attach(ctx, callback); } } ); return evtUnion; } /** https://docs.evt.land/api/evt/merge */ export function merge>( ctx: CtxLike, evts: readonly EvtUnion[] ): Evt>; export function merge>( evts: readonly EvtUnion[] ): Evt>; export function merge>( p1: CtxLike | readonly EvtUnion[], p2?: readonly EvtUnion[] ): Evt> { return "length" in p1 ? mergeImpl(undefined, p1) : mergeImpl(p1, p2!) ; }