nanoeffects 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +2 -0
  2. package/dist/{notrace/action-creator-Ls3Gy3jk.d.ts → action-creator-HFA_LZOH.d.ts} +2 -2
  3. package/dist/actions.d.ts +3 -3
  4. package/dist/actions.js +1 -1
  5. package/dist/bus-duCCrqrr.js +1 -0
  6. package/dist/{notrace/context-types-DQYBFJG4.d.ts → context-types-BNcs43eY.d.ts} +1 -1
  7. package/dist/context.d.ts +2 -2
  8. package/dist/dev.d.ts +2 -2
  9. package/dist/effects.d.ts +2 -2
  10. package/dist/index.d.ts +2 -3
  11. package/dist/index.js +1 -1
  12. package/dist/match.d.ts +1 -1
  13. package/dist/{module-COv9ZSzS.d.ts → module-DTf73Wdq.d.ts} +2 -2
  14. package/dist/{action-creator-CQlFgQm4.d.ts → notrace/action-creator-CbFf398i.d.ts} +2 -24
  15. package/dist/notrace/actions.d.ts +2 -2
  16. package/dist/notrace/actions.js +1 -1
  17. package/dist/notrace/bus-BkUtjPHp.js +1 -0
  18. package/dist/notrace/effects.d.ts +2 -2
  19. package/dist/notrace/index.d.ts +2 -3
  20. package/dist/notrace/index.js +1 -1
  21. package/dist/{plugin-15-kkZp0.d.ts → notrace/plugin-C5vIjxhR.d.ts} +8 -2
  22. package/dist/notrace/policies.d.ts +1 -1
  23. package/dist/notrace/redux.d.ts +1 -1
  24. package/dist/observable.d.ts +1 -1
  25. package/dist/oop.d.ts +1 -1
  26. package/dist/oop.js +1 -1
  27. package/dist/{notrace/plugin-W4pZY7mM.d.ts → plugin-Sy8z9IId.d.ts} +2 -2
  28. package/dist/policies.d.ts +2 -2
  29. package/dist/react.d.ts +2 -2
  30. package/dist/redux.d.ts +1 -1
  31. package/dist/scope.d.ts +2 -2
  32. package/dist/signal.d.ts +1 -1
  33. package/dist/signal.js +1 -1
  34. package/dist/trace.d.ts +2 -2
  35. package/dist/{types-C7ukMwE-.d.ts → types-DaZT158m.d.ts} +2 -2
  36. package/dist/{with-policy-_zP3OKGy.d.ts → with-policy-C_mX7S54.d.ts} +1 -1
  37. package/docs/package.md +2 -2
  38. package/docs/starter.md +69 -0
  39. package/docs/tracing.md +1 -1
  40. package/llms-full.txt +76 -3
  41. package/llms.txt +1 -0
  42. package/package.json +5 -4
  43. package/dist/bus-Cdw5ajKF.js +0 -1
  44. package/dist/context-types-qXxr_Grf.d.ts +0 -14
  45. package/dist/notrace/bus-G2AdGObY.js +0 -1
package/README.md CHANGED
@@ -15,6 +15,8 @@ npm install nanoeffects
15
15
 
16
16
  ESM only, no dependencies, types included.
17
17
 
18
+ Starting a new project? `npm create nanoeffects@latest my-app` makes a Vite app with a bus ([Docs](docs/starter.md)).
19
+
18
20
  Want to try it first? [Open the playground](https://stackblitz.com/github/nanoeffects/nanoeffects/tree/main/examples/playground): a search box with `debounce` and `latest`, running in your browser, no install. More playgrounds (React) and recipes: [Examples](examples/README.md).
19
21
 
20
22
  ## Create a bus
@@ -243,7 +243,7 @@ interface Bus<E extends EventMap> {
243
243
  }
244
244
  type BusOptions<E extends EventMap> = {
245
245
  /** Tracing of every task phase; make it with `createTracer` from `nanoeffects/trace`. */
246
- trace?: never;
246
+ trace?: Tracer;
247
247
  /**
248
248
  * Receives errors of handlers: thrown ones and rejections of async ones.
249
249
  * Without it handlers run like in a plain loop: the first error stops the
@@ -400,4 +400,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
400
400
  toString(): T;
401
401
  }
402
402
  //#endregion
403
- export { On as A, PayloadOf as B, EventKey as C, Handler as D, EventsOf as E, Tracer as F, TraceLogger as G, Task as H, anyEventType as I, UnsubscribeCallback as K, EffectName as L, WithType as M, commandCall as N, HandlerRef as O, createBus as P, EventMap as R, Emittable as S, EventPayload as T, Trace as U, Phase as V, TraceEvent as W, Commands as _, Scope as a, ContextOption as b, BoundForm as c, Action as d, AnyEvent as f, CommandCall as g, Command as h, WithPayload as i, WithContext as j, Off as k, Effect as l, BusOptions as m, Free as n, WithFields as o, Bus as p, FreeActionCreator as r, WithScope as s, ActionCreator as t, Effects as u, Context as v, EventLike as w, Emit as x, ContextOf as y, Keys as z };
403
+ export { HandlerRef as A, ListenerOptions as B, Emit as C, EventPayload as D, EventLike as E, createBus as F, TraceEvent as G, Phase as H, Tracer as I, TraceLogger as K, EffectName as L, On as M, WithContext as N, EventsOf as O, WithType as P, EventMap as R, ContextOption as S, EventKey as T, Task as U, PayloadOf as V, Trace as W, Command as _, EmitScope as a, Context as b, WithScope as c, Effects as d, Signaled as f, BusOptions as g, Bus as h, WithPayload as i, Off as j, Handler as k, BoundForm as l, AnyEvent as m, Free as n, Scope as o, Action as p, UnsubscribeCallback as q, FreeActionCreator as r, WithFields as s, ActionCreator as t, Effect as u, CommandCall as v, Emittable as w, ContextOf as x, Commands as y, Keys as z };
package/dist/actions.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { B as EventMap, G as Task, T as EventKey, U as PayloadOf, c as WithScope, h as Bus, n as Free, o as Scope, r as FreeActionCreator, t as ActionCreator } from "./action-creator-CQlFgQm4.js";
2
- import { r as Scoped, t as FieldsOfScope } from "./types-C7ukMwE-.js";
3
- import { a as createModule, c as CarryingCalls, d as commandsPlugin, f as createCommand, l as MadeCommand, n as ModuleApi, o as modulePlugin, r as ModuleContext, s as Binding, t as Module, u as bindHandler } from "./module-COv9ZSzS.js";
1
+ import { R as EventMap, T as EventKey, U as Task, V as PayloadOf, c as WithScope, h as Bus, n as Free, o as Scope, r as FreeActionCreator, t as ActionCreator } from "./action-creator-HFA_LZOH.js";
2
+ import { r as Scoped, t as FieldsOfScope } from "./types-DaZT158m.js";
3
+ import { a as createModule, c as CarryingCalls, d as commandsPlugin, f as createCommand, l as MadeCommand, n as ModuleApi, o as modulePlugin, r as ModuleContext, s as Binding, t as Module, u as bindHandler } from "./module-DTf73Wdq.js";
4
4
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
5
5
  //#region src/actions/action.d.ts
6
6
  type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
package/dist/actions.js CHANGED
@@ -1 +1 @@
1
- import{d as e,i as t,l as n,n as r,u as i}from"./context-CJGW6OWj.js";import{t as a}from"./event-0RIBGYqS.js";import{i as o}from"./bus-Cdw5ajKF.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";import{t as u}from"./scope-key-B7l7mUS5.js";const d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=d(a,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(t,r,i,a)=>{let o=t;o[n]=!0;try{S(t,r,i,a)}catch(t){e(`cancel listener`,t)}o[n]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,n,r={},a)=>{let l=g(t,n),u=e=>x(r[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,n,r,o)=>{let s=r,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=i(s,g),S(s,f,n,a))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,a):`error`in e?S(s,m,e.error,a):S(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(o||_(),Reflect.apply(t,null,[n,r]))).then(e=>(v({value:e}),e),t=>{if(l===`idle`)try{_()}catch(t){e(`pending listener`,t)}v({error:t})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,r){return typeof r==`object`?n?_(l,e,r,!1):Reflect.apply(l,null,[e,r]):d(o(T,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,a);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(e=[])=>n=>{let a=n.commands??y()(n),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=e=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(e,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(n,h),_=(e,t)=>{let n=Reflect.apply(o.handle,null,N(g,e,t));return i(f,n),n},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(n,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(n),l=n.emit,u,d=(t=!0)=>{if(u)return u;c.release(),n.emit===f&&(n.emit=l);let i=r({event:{type:`app`,payload:void 0},bus:n,tracer:n.trace});if(u={root:i,apps:s(i.ctx)},t)for(let t of e)u.apps.mount(t);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,n,e));n.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return n.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
1
+ import{d as e,i as t,l as n,n as r,u as i}from"./context-CJGW6OWj.js";import{t as a}from"./event-0RIBGYqS.js";import{r as o}from"./bus-duCCrqrr.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";import{t as u}from"./scope-key-B7l7mUS5.js";const d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=d(a,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(t,r,i,a)=>{let o=t;o[n]=!0;try{S(t,r,i,a)}catch(t){e(`cancel listener`,t)}o[n]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,n,r={},a)=>{let l=g(t,n),u=e=>x(r[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,n,r,o)=>{let s=r,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=i(s,g),S(s,f,n,a))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,a):`error`in e?S(s,m,e.error,a):S(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(o||_(),Reflect.apply(t,null,[n,r]))).then(e=>(v({value:e}),e),t=>{if(l===`idle`)try{_()}catch(t){e(`pending listener`,t)}v({error:t})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,r){return typeof r==`object`?n?_(l,e,r,!1):Reflect.apply(l,null,[e,r]):d(o(T,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,a);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(e=[])=>n=>{let a=n.commands??y()(n),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=e=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(e,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(n,h),_=(e,t)=>{let n=Reflect.apply(o.handle,null,N(g,e,t));return i(f,n),n},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(n,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(n),l=n.emit,u,d=(t=!0)=>{if(u)return u;c.release(),n.emit===f&&(n.emit=l);let i=r({event:{type:`app`,payload:void 0},bus:n,tracer:n.trace});if(u={root:i,apps:s(i.ctx)},t)for(let t of e)u.apps.mount(t);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,n,e));n.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return n.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
@@ -0,0 +1 @@
1
+ import{d as e,n as t,o as n,r}from"./context-CJGW6OWj.js";import{n as i}from"./promise-CSLpzwSR.js";import{n as a,t as o}from"./event-0RIBGYqS.js";const s=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},c=Symbol(),l=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,c,{value:e,enumerable:!1}),r},u=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&c in e)return e[c]},d=(e,t,n)=>Reflect.apply(e,null,[t,n]),f=(c={})=>{let l=s(),f=(e,t)=>l.add(o(e),t),p=(e,t)=>{let n=f(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(o(e),t)},h=(n,a)=>{let{onError:o}=c,{ctx:s}=t({event:a,bus:g,tracer:c.trace,parent:{ref:r()}});if(!o){n(a.payload,s);return}let l=t=>{try{o(t,a)}catch(t){e(`onError failed`,t)}};try{let e=n(a.payload,s);i(e)&&Promise.resolve(e).catch(l)}catch(e){l(e)}},g={on:f,once:p,off:m,emit:(e,i)=>{let s=o(e),f=a(e,i),p={type:s,payload:f},m=u(e),_=[...l.get(s),...l.get(`*`)];_.length===0&&!m&&c.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:e}=t({event:p,bus:g,tracer:c.trace,parent:{ref:r()}}),i=g.commands?.run??d;return n(e,`command`,()=>i(m,f,e))}},use:e=>e(g),ctx:c.context,trace:c.trace};return g};export{f as n,l as r,u as t};
@@ -1,4 +1,4 @@
1
- import { R as EventMap, y as ContextOf } from "./action-creator-Ls3Gy3jk.js";
1
+ import { R as EventMap, x as ContextOf } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/core/context-types.d.ts
3
3
  /** What a function that makes the fields of a task gets to see. */
4
4
  type ContextTask = {
package/dist/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as EventMap, N as WithContext, h as Bus } from "./action-creator-CQlFgQm4.js";
2
- import { n as NoClash, t as ContextTask } from "./context-types-qXxr_Grf.js";
1
+ import { N as WithContext, R as EventMap, h as Bus } from "./action-creator-HFA_LZOH.js";
2
+ import { n as NoClash, t as ContextTask } from "./context-types-BNcs43eY.js";
3
3
  //#region src/context/plugin.d.ts
4
4
  /**
5
5
  * Puts `fields` on the context of every task of the bus: a store, a client, a
package/dist/dev.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as EventMap, Y as UnsubscribeCallback, h as Bus } from "./action-creator-CQlFgQm4.js";
2
- import { i as WithApp, n as ModuleApi } from "./module-COv9ZSzS.js";
1
+ import { R as EventMap, h as Bus, q as UnsubscribeCallback } from "./action-creator-HFA_LZOH.js";
2
+ import { i as WithApp, n as ModuleApi } from "./module-DTf73Wdq.js";
3
3
  //#region src/dev/types.d.ts
4
4
  /** The parts of what `modulePlugin` returned that the diagnostics report. */
5
5
  type ReportedApp<E extends EventMap> = Pick<ModuleApi<E>, "mount" | "unmount" | "isMounted">;
package/dist/effects.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as EventMap, G as Task, u as Effect } from "./action-creator-CQlFgQm4.js";
2
- import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-15-kkZp0.js";
1
+ import { R as EventMap, U as Task, u as Effect } from "./action-creator-HFA_LZOH.js";
2
+ import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-Sy8z9IId.js";
3
3
  //#region src/utils/onAbort.d.ts
4
4
  export declare const onAbort: (ctx: {
5
5
  signal?: AbortSignal | undefined;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { A as HandlerRef, B as EventMap, C as Emit, D as EventPayload, E as EventLike, F as commandCall, G as Task, I as createBus, J as TraceLogger, K as Trace, L as Tracer, M as On, N as WithContext, O as EventsOf, P as WithType, R as anyEventType, S as ContextOption, T as EventKey, U as PayloadOf, V as Keys, W as Phase, Y as UnsubscribeCallback, _ as Command, b as Context, g as BusOptions, h as Bus, i as WithPayload, j as Off, k as Handler, m as AnyEvent, p as Action, q as TraceEvent, v as CommandCall, w as Emittable, x as ContextOf, y as Commands, z as EffectName } from "./action-creator-CQlFgQm4.js";
2
- import { n as NoClash, t as ContextTask } from "./context-types-qXxr_Grf.js";
3
- export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type ContextTask, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type NoClash, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, createBus };
1
+ import { A as HandlerRef, C as Emit, D as EventPayload, E as EventLike, F as createBus, M as On, N as WithContext, O as EventsOf, P as WithType, R as EventMap, S as ContextOption, T as EventKey, U as Task, V as PayloadOf, _ as Command, b as Context, g as BusOptions, h as Bus, i as WithPayload, j as Off, k as Handler, m as AnyEvent, p as Action, q as UnsubscribeCallback, v as CommandCall, w as Emittable, x as ContextOf, y as Commands, z as Keys } from "./action-creator-HFA_LZOH.js";
2
+ export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, createBus };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{a as anyEventType,t as commandCall,r as createBus}from"./bus-Cdw5ajKF.js";
1
+ export{n as createBus}from"./bus-duCCrqrr.js";
package/dist/match.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as EventMap, D as EventPayload, G as Task, Y as UnsubscribeCallback, h as Bus, p as Action } from "./action-creator-CQlFgQm4.js";
1
+ import { D as EventPayload, R as EventMap, U as Task, h as Bus, p as Action, q as UnsubscribeCallback } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/match/plugin.d.ts
3
3
  /** A function over the action of an event: `{ type, payload }`. */
4
4
  type Predicate<E extends EventMap> = (action: Action<E>) => boolean;
@@ -1,5 +1,5 @@
1
- import { B as EventMap, G as Task, U as PayloadOf, Y as UnsubscribeCallback, _ as Command, b as Context, c as WithScope, h as Bus, o as Scope, v as CommandCall, y as Commands } from "./action-creator-CQlFgQm4.js";
2
- import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-C7ukMwE-.js";
1
+ import { R as EventMap, U as Task, V as PayloadOf, _ as Command, b as Context, c as WithScope, h as Bus, o as Scope, q as UnsubscribeCallback, v as CommandCall, y as Commands } from "./action-creator-HFA_LZOH.js";
2
+ import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-DaZT158m.js";
3
3
  //#region src/actions/command.d.ts
4
4
  /** What `createCommand` returns: a command that also tells whether an action is of its type. */
5
5
  type MadeCommand<P, R, T extends string> = Command<P, R> & {
@@ -10,28 +10,6 @@ type Keys<E> = keyof E & string;
10
10
  type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
11
11
  type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command" | "emit";
12
12
  type Phase = "start" | "done" | "error" | "cancel" | "drop";
13
- type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
14
- id: number;
15
- /** Id of the task that started this one, if it has one. */
16
- parentId?: number;
17
- type: K;
18
- effect: EffectName;
19
- phase: Phase;
20
- payload: E[K];
21
- error?: unknown;
22
- /** The flow the task belongs to: its own, or the nearest ancestor’s; absent without one. */
23
- traceGroupId?: string;
24
- /** The id of the root task of the chain; absent on the root itself. */
25
- rootId?: number;
26
- }; }[Keys<E>];
27
- /**
28
- * The contract of every trace logger: receives each task phase of a bus.
29
- * Adapters in `nanoeffects/trace` are factories that return one; pass it
30
- * through `createTracer` to `createBus({ trace })`.
31
- */
32
- type TraceLogger<E = Record<string, unknown>> = (event: TraceEvent<E>) => void;
33
- /** One logger or several; a throwing logger never breaks the task or the others. */
34
- type Trace<E = Record<string, unknown>> = TraceLogger<E> | readonly TraceLogger<E>[];
35
13
  type UnsubscribeCallback = () => void;
36
14
  //#endregion
37
15
  //#region src/core/store.d.ts
@@ -243,7 +221,7 @@ interface Bus<E extends EventMap> {
243
221
  }
244
222
  type BusOptions<E extends EventMap> = {
245
223
  /** Tracing of every task phase; make it with `createTracer` from `nanoeffects/trace`. */
246
- trace?: Tracer;
224
+ trace?: never;
247
225
  /**
248
226
  * Receives errors of handlers: thrown ones and rejections of async ones.
249
227
  * Without it handlers run like in a plain loop: the first error stops the
@@ -400,4 +378,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
400
378
  toString(): T;
401
379
  }
402
380
  //#endregion
403
- export { HandlerRef as A, EventMap as B, Emit as C, EventPayload as D, EventLike as E, commandCall as F, Task as G, ListenerOptions as H, createBus as I, TraceLogger as J, Trace as K, Tracer as L, On as M, WithContext as N, EventsOf as O, WithType as P, anyEventType as R, ContextOption as S, EventKey as T, PayloadOf as U, Keys as V, Phase as W, UnsubscribeCallback as Y, Command as _, EmitScope as a, Context as b, WithScope as c, Effects as d, Signaled as f, BusOptions as g, Bus as h, WithPayload as i, Off as j, Handler as k, BoundForm as l, AnyEvent as m, Free as n, Scope as o, Action as p, TraceEvent as q, FreeActionCreator as r, WithFields as s, ActionCreator as t, Effect as u, CommandCall as v, Emittable as w, ContextOf as x, Commands as y, EffectName as z };
381
+ export { On as A, EventKey as C, Handler as D, EventsOf as E, Keys as F, PayloadOf as I, Task as L, WithType as M, createBus as N, HandlerRef as O, EventMap as P, UnsubscribeCallback as R, Emittable as S, EventPayload as T, Commands as _, Scope as a, ContextOption as b, BoundForm as c, Action as d, AnyEvent as f, CommandCall as g, Command as h, WithPayload as i, WithContext as j, Off as k, Effect as l, BusOptions as m, Free as n, WithFields as o, Bus as p, FreeActionCreator as r, WithScope as s, ActionCreator as t, Effects as u, Context as v, EventLike as w, Emit as x, ContextOf as y };
@@ -1,5 +1,5 @@
1
- import { B as PayloadOf, C as EventKey, H as Task, K as UnsubscribeCallback, R as EventMap, _ as Commands, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context } from "./action-creator-Ls3Gy3jk.js";
2
- import { t as BoundOf } from "./plugin-W4pZY7mM.js";
1
+ import { C as EventKey, I as PayloadOf, L as Task, P as EventMap, R as UnsubscribeCallback, _ as Commands, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context } from "./action-creator-CbFf398i.js";
2
+ import { t as BoundOf } from "./plugin-C5vIjxhR.js";
3
3
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
4
4
  //#region src/scope/types.d.ts
5
5
  /**
@@ -1 +1 @@
1
- import{c as e,i as t,l as n,n as r,s as i}from"./context-yYU3_9lq.js";import{a,r as o}from"./bus-G2AdGObY.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";const u=Symbol.for(`nanoeffects.scope`),d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=d(a,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(e,t,r,a)=>{let o=e;o[i]=!0;try{S(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,r,i={},a)=>{let l=g(t,r),u=e=>x(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,r,i,o)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),S(s,f,r,a))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,a):`error`in e?S(s,m,e.error,a):S(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(o||_(),Reflect.apply(t,null,[r,i]))).then(e=>(v({value:e}),e),e=>{if(l===`idle`)try{_()}catch(e){n(`pending listener`,e)}v({error:e})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,n){return typeof n==`object`?r?_(l,e,n,!1):Reflect.apply(l,null,[e,n]):d(o(T,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,a);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(n=[])=>i=>{let a=i.commands??y()(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=n=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(n,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(i,h),_=(t,n)=>{let r=Reflect.apply(o.handle,null,N(g,t,n));return e(f,r),r},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(i,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(i),l=i.emit,u,d=(e=!0)=>{if(u)return u;c.release(),i.emit===f&&(i.emit=l);let t=r({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace});if(u={root:t,apps:s(t.ctx)},e)for(let e of n)u.apps.mount(e);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,i,e));i.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return i.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
1
+ import{c as e,i as t,l as n,n as r,s as i}from"./context-yYU3_9lq.js";import{n as a,r as o}from"./bus-BkUtjPHp.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";const u=Symbol.for(`nanoeffects.scope`),d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(a(s,e,r),n)}let o=Object.assign(i,{type:e,match:r}),s=d(o,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function a(e,t){if(t)return i(o(e),t);let n=e.map(([e,t])=>i(o(e),t));return()=>{for(let e of n)e()}}a(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:a};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(e,t,r,a)=>{let o=e;o[i]=!0;try{S(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,r,i={},o)=>{let l=g(t,r),u=e=>x(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,r,i,a)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,o))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),S(s,f,r,o))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,o):`error`in e?S(s,m,e.error,o):S(s,p,e.value,o))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(a||_(),Reflect.apply(t,null,[r,i]))).then(e=>(v({value:e}),e),e=>{if(l===`idle`)try{_()}catch(e){n(`pending listener`,e)}v({error:e})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,n){return typeof n==`object`?r?_(l,e,n,!1):Reflect.apply(l,null,[e,n]):d(a(T,t,e),o)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,o);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(n=[])=>i=>{let a=i.commands??y()(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=n=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(n,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(i,h),_=(t,n)=>{let r=Reflect.apply(o.handle,null,N(g,t,n));return e(f,r),r},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(i,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(i),l=i.emit,u,d=(e=!0)=>{if(u)return u;c.release(),i.emit===f&&(i.emit=l);let t=r({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace});if(u={root:t,apps:s(t.ctx)},e)for(let e of n)u.apps.mount(e);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,i,e));i.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return i.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
@@ -0,0 +1 @@
1
+ import{a as e,l as t,n,r}from"./context-yYU3_9lq.js";import{n as i}from"./promise-CSLpzwSR.js";const a=e=>typeof e==`string`?e:e.type,o=(e,t)=>typeof e==`object`?e.payload:t,s=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},c=Symbol(),l=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,c,{value:e,enumerable:!1}),r},u=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&c in e)return e[c]},d=(e,t,n)=>Reflect.apply(e,null,[t,n]),f=(c={})=>{let l=s(),f=(e,t)=>l.add(a(e),t),p=(e,t)=>{let n=f(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(a(e),t)},h=(e,a)=>{let{onError:o}=c,{ctx:s}=n({event:a,bus:g,tracer:c.trace,parent:{ref:r()}});if(!o){e(a.payload,s);return}let l=e=>{try{o(e,a)}catch(e){t(`onError failed`,e)}};try{let t=e(a.payload,s);i(t)&&Promise.resolve(t).catch(l)}catch(e){l(e)}},g={on:f,once:p,off:m,emit:(t,i)=>{let s=a(t),f=o(t,i),p={type:s,payload:f},m=u(t),_=[...l.get(s),...l.get(`*`)];_.length===0&&!m&&c.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:t}=n({event:p,bus:g,tracer:c.trace,parent:{ref:r()}}),i=g.commands?.run??d;return e(t,`command`,()=>i(m,f,t))}},use:e=>e(g),ctx:c.context,trace:c.trace};return g};export{l as n,a as r,f as t};
@@ -1,5 +1,5 @@
1
- import { H as Task, R as EventMap, l as Effect } from "./action-creator-Ls3Gy3jk.js";
2
- import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-W4pZY7mM.js";
1
+ import { L as Task, P as EventMap, l as Effect } from "./action-creator-CbFf398i.js";
2
+ import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-C5vIjxhR.js";
3
3
  //#region src/utils/onAbort.d.ts
4
4
  export declare const onAbort: (ctx: {
5
5
  signal?: AbortSignal | undefined;
@@ -1,3 +1,2 @@
1
- import { A as On, B as PayloadOf, C as EventKey, D as Handler, E as EventsOf, F as Tracer, G as TraceLogger, H as Task, I as anyEventType, K as UnsubscribeCallback, L as EffectName, M as WithType, N as commandCall, O as HandlerRef, P as createBus, R as EventMap, S as Emittable, T as EventPayload, U as Trace, V as Phase, W as TraceEvent, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf, z as Keys } from "./action-creator-Ls3Gy3jk.js";
2
- import { n as NoClash, t as ContextTask } from "./context-types-DQYBFJG4.js";
3
- export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type ContextTask, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type NoClash, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, createBus };
1
+ import { A as On, C as EventKey, D as Handler, E as EventsOf, F as Keys, I as PayloadOf, L as Task, M as WithType, N as createBus, O as HandlerRef, P as EventMap, R as UnsubscribeCallback, S as Emittable, T as EventPayload, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf } from "./action-creator-CbFf398i.js";
2
+ export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, createBus };
@@ -1 +1 @@
1
- export{i as anyEventType,t as commandCall,n as createBus}from"./bus-G2AdGObY.js";
1
+ export{t as createBus}from"./bus-BkUtjPHp.js";
@@ -1,5 +1,11 @@
1
- import { B as EventMap, N as WithContext, V as Keys, b as Context, d as Effects, h as Bus, l as BoundForm } from "./action-creator-CQlFgQm4.js";
2
- import { n as NoClash } from "./context-types-qXxr_Grf.js";
1
+ import { F as Keys, P as EventMap, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, y as ContextOf } from "./action-creator-CbFf398i.js";
2
+ //#region src/core/context-types.d.ts
3
+ /**
4
+ * `unknown` when none of the `fields` is already a context field of the bus,
5
+ * else `never`: the call does not compile. Used as `bus: Bus<E> & NoClash<…>`.
6
+ */
7
+ type NoClash<Fields extends object, E extends EventMap> = [keyof Fields & keyof ContextOf<E>] extends [never] ? unknown : never;
8
+ //#endregion
3
9
  //#region src/utils/delay.d.ts
4
10
  /**
5
11
  * Resolves after `ms`, or rejects early if `ctx.signal` aborts. `ms` can be a
@@ -1,4 +1,4 @@
1
- import { B as PayloadOf, H as Task, R as EventMap } from "./action-creator-Ls3Gy3jk.js";
1
+ import { I as PayloadOf, L as Task, P as EventMap } from "./action-creator-CbFf398i.js";
2
2
  //#region src/policies/keyed.d.ts
3
3
  /** Options shared by every policy that can keep its state per key. */
4
4
  type KeyOption<P> = {
@@ -1,4 +1,4 @@
1
- import { R as EventMap, p as Bus } from "./action-creator-Ls3Gy3jk.js";
1
+ import { P as EventMap, p as Bus } from "./action-creator-CbFf398i.js";
2
2
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
3
3
  //#region src/store/redux/middleware.d.ts
4
4
  /** What Redux passes through a middleware: an action is a plain object with a `type`. */
@@ -1,4 +1,4 @@
1
- import { B as EventMap, V as Keys, h as Bus } from "./action-creator-CQlFgQm4.js";
1
+ import { R as EventMap, h as Bus, z as Keys } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/observable.d.ts
3
3
  declare global {
4
4
  interface SymbolConstructor {
package/dist/oop.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as EventMap, H as ListenerOptions, _ as Command, h as Bus, t as ActionCreator } from "./action-creator-CQlFgQm4.js";
1
+ import { B as ListenerOptions, R as EventMap, _ as Command, h as Bus, t as ActionCreator } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/oop/types.d.ts
3
3
  type Slots = "ctx" | "commands" | "trace" | "addContext" | "applyScope" | "fitScope" | "app" | "use";
4
4
  type AnyFunction = (...args: never[]) => unknown;
package/dist/oop.js CHANGED
@@ -1 +1 @@
1
- import{r as e}from"./bus-Cdw5ajKF.js";const t=/* @__PURE__ */ new WeakMap,n=e=>typeof e==`function`,r=e=>Reflect.ownKeys(e).flatMap(t=>{let r=Reflect.getOwnPropertyDescriptor(e,t)?.value;return n(r)?[{key:t,value:r}]:[]}),i=/* @__PURE__ */ new WeakMap,a=e=>{let n=i.get(e);if(n)return n;let a=/* @__PURE__ */ new Set,o=[];for(let n=e;n&&n!==Object.prototype;n=Reflect.getPrototypeOf(n))for(let{key:e,value:i}of r(n)){if(e===`constructor`||a.has(e))continue;a.add(e);let n=t.get(i);n&&o.push({key:e,method:i,spec:n})}return i.set(e,o),o},o=/* @__PURE__ */ new WeakMap,s=e=>typeof e==`object`&&!!e||typeof e==`function`,c=e=>{let t=o.get(e);if(t)return t;let n=/* @__PURE__ */ new Set;return o.set(e,n),n},l=e=>{if(typeof e==`string`)return e;if(s(e)){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},u=(e,t,n)=>Reflect.apply(Reflect.get(e,t),e,n),d=(e,t,n,r)=>{let[i,a,...o]=r,s=c(e),l={event:i,handler:a,off:()=>{}},d=u(t,n,[i,n===`once`?(e,t)=>(s.delete(l),typeof a==`function`?Reflect.apply(a,null,[e,t]):void 0):a,...o]),f=typeof d==`function`?()=>d():()=>{};return l.off=f,s.add(l),()=>{s.delete(l),f()}},f=(e,t,n)=>{let[r,i]=n,a=c(e);r===void 0&&a.clear();for(let e of[...a])Object.is(l(e.event),l(r))&&(i===void 0||e.handler===i)&&(a.delete(e),e.off());return u(t,`off`,n)},p=e=>{if(!s(e))return;let t=o.get(e);if(t){o.delete(e);for(let e of t)e.off()}},m=/* @__PURE__ */ new Set([`on`,`once`,`off`,`emit`,`ctx`,`commands`,`trace`,`addContext`,`applyScope`,`fitScope`,`app`,`use`]),h=Reflect.get(Symbol,`dispose`),g=e=>typeof e==`function`;var _=class{};const v=(e,t,n,r)=>{n in t||Object.defineProperty(e,n,{configurable:!0,enumerable:!1,...r})},y=/* @__PURE__ */ new WeakMap,b=(e,t)=>{let n=y.get(e);if(n)return n;let r={on:(...n)=>d(e,t,`on`,n),once:(...n)=>d(e,t,`once`,n),off:(...n)=>f(e,t,n)};return y.set(e,r),r},x=(e,t)=>(...n)=>Reflect.apply(Reflect.get(e,t),e,n),S=(e,t)=>{for(let{method:n,spec:r}of a(Reflect.getPrototypeOf(e)??{})){let i=(t,r)=>Reflect.apply(n,e,[t,r]),a=r.wrap?r.wrap(i):i,o=r.once?`once`:`on`;d(e,t,o,[r.event,a,r.options])}},C=(e,t,n)=>{for(let r of[`on`,`once`,`off`])v(e,t,r,{get(){return b(this,n)[r]}});v(e,t,`emit`,{value:x(n,`emit`)});for(let[r,i]of Object.entries(n))typeof i==`function`&&!m.has(r)&&v(e,t,r,{value:x(n,r)});let r=function(){p(this)};v(e,t,`dispose`,{value:r}),h&&v(e,t,h,{value:r}),v(e,t,`bus`,{get:()=>n})},w=(e,t)=>{let n=function(...r){let i=Reflect.construct(t,r,new.target??n);return S(i,e),i};return Object.setPrototypeOf(n,t),n.prototype=Object.create(t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"name",{value:t.name,configurable:!0}),`bus`in t||Object.defineProperty(n,"bus",{value:e,configurable:!0}),C(n.prototype,t.prototype,e),n};function T(t,n){return g(t)?w(e(),t):w(t,n??_)}function E(e){return t=>e?T(e,t):T(t)}const D=e=>{let[t,n,r]=e;return typeof n==`string`||typeof n==`symbol`?Reflect.get(Object(r),`value`):t},O=(e,n,r,i)=>((...a)=>{let o=D(a);if(typeof o==`function`){let a=typeof n==`function`?n:void 0,s=typeof n==`function`?r:n??r;t.set(o,{event:e,wrap:a,once:i,options:s})}});function k(e,t,n){return O(e,t,n,!1)}function A(e,t,n){return O(e,t,n,!0)}const j=/* @__PURE__ */ new WeakMap,M=t=>{let n=j.get(t);if(n)return n;let r=e();return j.set(t,r),r},N=[`on`,`once`,`off`,`emit`],P=e=>{for(let t of N){let n=Reflect.get(e,t);Reflect.set(e,t,n.bind(e))}};var F=class{constructor(){P(this),S(this,M(this))}get bus(){return M(this)}dispose(){p(this)}};const I={on(...e){return d(this,M(this),`on`,e)},once(...e){return d(this,M(this),`once`,e)},off(...e){return f(this,M(this),e)},emit(...e){let t=M(this);return Reflect.apply(Reflect.get(t,`emit`),t,e)}};for(let e of N)Object.defineProperty(F.prototype,e,{configurable:!0,writable:!0,value:I[e]});h&&Object.defineProperty(F.prototype,h,{configurable:!0,value:function(){this.dispose()}});export{F as Emitter,k as On,A as Once,E as WithBus,p as disposeBus,T as extendBus};
1
+ import{n as e}from"./bus-duCCrqrr.js";const t=/* @__PURE__ */ new WeakMap,n=e=>typeof e==`function`,r=e=>Reflect.ownKeys(e).flatMap(t=>{let r=Reflect.getOwnPropertyDescriptor(e,t)?.value;return n(r)?[{key:t,value:r}]:[]}),i=/* @__PURE__ */ new WeakMap,a=e=>{let n=i.get(e);if(n)return n;let a=/* @__PURE__ */ new Set,o=[];for(let n=e;n&&n!==Object.prototype;n=Reflect.getPrototypeOf(n))for(let{key:e,value:i}of r(n)){if(e===`constructor`||a.has(e))continue;a.add(e);let n=t.get(i);n&&o.push({key:e,method:i,spec:n})}return i.set(e,o),o},o=/* @__PURE__ */ new WeakMap,s=e=>typeof e==`object`&&!!e||typeof e==`function`,c=e=>{let t=o.get(e);if(t)return t;let n=/* @__PURE__ */ new Set;return o.set(e,n),n},l=e=>{if(typeof e==`string`)return e;if(s(e)){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},u=(e,t,n)=>Reflect.apply(Reflect.get(e,t),e,n),d=(e,t,n,r)=>{let[i,a,...o]=r,s=c(e),l={event:i,handler:a,off:()=>{}},d=u(t,n,[i,n===`once`?(e,t)=>(s.delete(l),typeof a==`function`?Reflect.apply(a,null,[e,t]):void 0):a,...o]),f=typeof d==`function`?()=>d():()=>{};return l.off=f,s.add(l),()=>{s.delete(l),f()}},f=(e,t,n)=>{let[r,i]=n,a=c(e);r===void 0&&a.clear();for(let e of[...a])Object.is(l(e.event),l(r))&&(i===void 0||e.handler===i)&&(a.delete(e),e.off());return u(t,`off`,n)},p=e=>{if(!s(e))return;let t=o.get(e);if(t){o.delete(e);for(let e of t)e.off()}},m=/* @__PURE__ */ new Set([`on`,`once`,`off`,`emit`,`ctx`,`commands`,`trace`,`addContext`,`applyScope`,`fitScope`,`app`,`use`]),h=Reflect.get(Symbol,`dispose`),g=e=>typeof e==`function`;var _=class{};const v=(e,t,n,r)=>{n in t||Object.defineProperty(e,n,{configurable:!0,enumerable:!1,...r})},y=/* @__PURE__ */ new WeakMap,b=(e,t)=>{let n=y.get(e);if(n)return n;let r={on:(...n)=>d(e,t,`on`,n),once:(...n)=>d(e,t,`once`,n),off:(...n)=>f(e,t,n)};return y.set(e,r),r},x=(e,t)=>(...n)=>Reflect.apply(Reflect.get(e,t),e,n),S=(e,t)=>{for(let{method:n,spec:r}of a(Reflect.getPrototypeOf(e)??{})){let i=(t,r)=>Reflect.apply(n,e,[t,r]),a=r.wrap?r.wrap(i):i,o=r.once?`once`:`on`;d(e,t,o,[r.event,a,r.options])}},C=(e,t,n)=>{for(let r of[`on`,`once`,`off`])v(e,t,r,{get(){return b(this,n)[r]}});v(e,t,`emit`,{value:x(n,`emit`)});for(let[r,i]of Object.entries(n))typeof i==`function`&&!m.has(r)&&v(e,t,r,{value:x(n,r)});let r=function(){p(this)};v(e,t,`dispose`,{value:r}),h&&v(e,t,h,{value:r}),v(e,t,`bus`,{get:()=>n})},w=(e,t)=>{let n=function(...r){let i=Reflect.construct(t,r,new.target??n);return S(i,e),i};return Object.setPrototypeOf(n,t),n.prototype=Object.create(t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"name",{value:t.name,configurable:!0}),`bus`in t||Object.defineProperty(n,"bus",{value:e,configurable:!0}),C(n.prototype,t.prototype,e),n};function T(t,n){return g(t)?w(e(),t):w(t,n??_)}function E(e){return t=>e?T(e,t):T(t)}const D=e=>{let[t,n,r]=e;return typeof n==`string`||typeof n==`symbol`?Reflect.get(Object(r),`value`):t},O=(e,n,r,i)=>((...a)=>{let o=D(a);if(typeof o==`function`){let a=typeof n==`function`?n:void 0,s=typeof n==`function`?r:n??r;t.set(o,{event:e,wrap:a,once:i,options:s})}});function k(e,t,n){return O(e,t,n,!1)}function A(e,t,n){return O(e,t,n,!0)}const j=/* @__PURE__ */ new WeakMap,M=t=>{let n=j.get(t);if(n)return n;let r=e();return j.set(t,r),r},N=[`on`,`once`,`off`,`emit`],P=e=>{for(let t of N){let n=Reflect.get(e,t);Reflect.set(e,t,n.bind(e))}};var F=class{constructor(){P(this),S(this,M(this))}get bus(){return M(this)}dispose(){p(this)}};const I={on(...e){return d(this,M(this),`on`,e)},once(...e){return d(this,M(this),`once`,e)},off(...e){return f(this,M(this),e)},emit(...e){let t=M(this);return Reflect.apply(Reflect.get(t,`emit`),t,e)}};for(let e of N)Object.defineProperty(F.prototype,e,{configurable:!0,writable:!0,value:I[e]});h&&Object.defineProperty(F.prototype,h,{configurable:!0,value:function(){this.dispose()}});export{F as Emitter,k as On,A as Once,E as WithBus,p as disposeBus,T as extendBus};
@@ -1,5 +1,5 @@
1
- import { R as EventMap, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, z as Keys } from "./action-creator-Ls3Gy3jk.js";
2
- import { n as NoClash } from "./context-types-DQYBFJG4.js";
1
+ import { N as WithContext, R as EventMap, b as Context, d as Effects, h as Bus, l as BoundForm, z as Keys } from "./action-creator-HFA_LZOH.js";
2
+ import { n as NoClash } from "./context-types-BNcs43eY.js";
3
3
  //#region src/utils/delay.d.ts
4
4
  /**
5
5
  * Resolves after `ms`, or rejects early if `ctx.signal` aborts. `ms` can be a
@@ -1,5 +1,5 @@
1
- import { B as EventMap, G as Task } from "./action-creator-CQlFgQm4.js";
2
- import { n as withPolicy, t as PolicyFunction } from "./with-policy-_zP3OKGy.js";
1
+ import { R as EventMap, U as Task } from "./action-creator-HFA_LZOH.js";
2
+ import { n as withPolicy, t as PolicyFunction } from "./with-policy-C_mX7S54.js";
3
3
  //#region src/policies/keyed.d.ts
4
4
  /** Options shared by every policy that can keep its state per key. */
5
5
  type KeyOption<P> = {
package/dist/react.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { B as EventMap, G as Task, T as EventKey, h as Bus, r as FreeActionCreator, t as ActionCreator } from "./action-creator-CQlFgQm4.js";
1
+ import { R as EventMap, T as EventKey, U as Task, h as Bus, r as FreeActionCreator, t as ActionCreator } from "./action-creator-HFA_LZOH.js";
2
2
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
3
- import { t as PolicyFunction } from "./with-policy-_zP3OKGy.js";
3
+ import { t as PolicyFunction } from "./with-policy-C_mX7S54.js";
4
4
  //#region src/react/plugin.d.ts
5
5
  /** Tells whether two values are the same: `Object.is` unless the caller gives another. */
6
6
  type Equals<V> = (previous: V, next: V) => boolean;
package/dist/redux.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as EventMap, h as Bus } from "./action-creator-CQlFgQm4.js";
1
+ import { R as EventMap, h as Bus } from "./action-creator-HFA_LZOH.js";
2
2
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
3
3
  //#region src/store/redux/middleware.d.ts
4
4
  /** What Redux passes through a middleware: an action is a plain object with a `type`. */
package/dist/scope.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as EventMap, a as EmitScope, d as Effects, f as Signaled, h as Bus, o as Scope, u as Effect } from "./action-creator-CQlFgQm4.js";
2
- import { n as ScopeSlots, r as Scoped } from "./types-C7ukMwE-.js";
1
+ import { R as EventMap, a as EmitScope, d as Effects, f as Signaled, h as Bus, o as Scope, u as Effect } from "./action-creator-HFA_LZOH.js";
2
+ import { n as ScopeSlots, r as Scoped } from "./types-DaZT158m.js";
3
3
  //#region src/scope/effect.d.ts
4
4
  /**
5
5
  * Marks a function whose first parameter is `{ signal }` as an effect, so that
package/dist/signal.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as EventMap, C as Emit, E as EventLike, a as EmitScope, c as WithScope, h as Bus, v as CommandCall } from "./action-creator-CQlFgQm4.js";
1
+ import { C as Emit, E as EventLike, R as EventMap, a as EmitScope, c as WithScope, h as Bus, v as CommandCall } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/signal/plugin.d.ts
3
3
  /** What the second argument of `emit` takes besides the fields of a scope. */
4
4
  type SignalOption = {
package/dist/signal.js CHANGED
@@ -1 +1 @@
1
- import{u as e}from"./context-CJGW6OWj.js";import{n as t}from"./promise-CSLpzwSR.js";import{n}from"./bus-Cdw5ajKF.js";const r=e=>typeof e==`object`&&!!e,i=(e,t)=>{let n=t[0];if(!r(n)||!r(e)&&typeof e!=`function`)return;let i=Reflect.get(n,`signal`);return i instanceof AbortSignal?i:void 0},a=(r,i,a,o)=>{let s=e({signal:r},e=>{for(let{target:t}of i)t.abort(e)});return t(o)?o.then(s,s):n(a)&&s(),o},o=()=>e=>{let t,n,r=e.addContext;e.addContext=e=>{r?.(e),t?.push({target:e}),n?.aborted&&e.abort(n.reason)};let o=e.emit;return e.emit=(e,...r)=>{let s=i(e,r);if(!(s||t))return o(e,...r);let c=t,l=n,u=[];t=s?u:void 0,n=s;let d;try{d=o(e,...r)}finally{t=c,n=l}return s?a(s,u,e,d):d},e};export{o as signalPlugin};
1
+ import{u as e}from"./context-CJGW6OWj.js";import{n as t}from"./promise-CSLpzwSR.js";import{t as n}from"./bus-duCCrqrr.js";const r=e=>typeof e==`object`&&!!e,i=(e,t)=>{let n=t[0];if(!r(n)||!r(e)&&typeof e!=`function`)return;let i=Reflect.get(n,`signal`);return i instanceof AbortSignal?i:void 0},a=(r,i,a,o)=>{let s=e({signal:r},e=>{for(let{target:t}of i)t.abort(e)});return t(o)?o.then(s,s):n(a)&&s(),o},o=()=>e=>{let t,n,r=e.addContext;e.addContext=e=>{r?.(e),t?.push({target:e}),n?.aborted&&e.abort(n.reason)};let o=e.emit;return e.emit=(e,...r)=>{let s=i(e,r);if(!(s||t))return o(e,...r);let c=t,l=n,u=[];t=s?u:void 0,n=s;let d;try{d=o(e,...r)}finally{t=c,n=l}return s?a(s,u,e,d):d},e};export{o as signalPlugin};
package/dist/trace.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as EventMap, J as TraceLogger, K as Trace, L as Tracer, W as Phase, h as Bus, q as TraceEvent, z as EffectName } from "./action-creator-CQlFgQm4.js";
1
+ import { G as TraceEvent, H as Phase, I as Tracer, K as TraceLogger, L as EffectName, R as EventMap, W as Trace, h as Bus } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/trace/console.d.ts
3
3
  type ConsoleLoggerOptions = {
4
4
  /** Defaults to `globalThis.console`. */
@@ -224,4 +224,4 @@ type TracerOptions = {
224
224
  */
225
225
  export declare const createTracer: <E = Record<string, unknown>>(trace: Trace<E>, options?: TracerOptions) => Tracer;
226
226
  //#endregion
227
- export type { ConsoleLoggerOptions, PayloadMode, PerformanceLoggerOptions, PolicyStage, PolicyStages, Recorder, ReduxDevtoolsOptions, ReduxDevtoolsState, ReduxExtension, TracerOptions };
227
+ export type { ConsoleLoggerOptions, EffectName, PayloadMode, PerformanceLoggerOptions, Phase, PolicyStage, PolicyStages, Recorder, ReduxDevtoolsOptions, ReduxDevtoolsState, ReduxExtension, Trace, TraceEvent, TraceLogger, Tracer, TracerOptions };
@@ -1,5 +1,5 @@
1
- import { B as EventMap, d as Effects, o as Scope, s as WithFields } from "./action-creator-CQlFgQm4.js";
2
- import { t as BoundOf } from "./plugin-15-kkZp0.js";
1
+ import { R as EventMap, d as Effects, o as Scope, s as WithFields } from "./action-creator-HFA_LZOH.js";
2
+ import { t as BoundOf } from "./plugin-Sy8z9IId.js";
3
3
  //#region src/scope/types.d.ts
4
4
  /**
5
5
  * The slots `scopePlugin` fills for `modulePlugin`. They are not on `Bus`: a bus
@@ -1,4 +1,4 @@
1
- import { B as EventMap, G as Task, U as PayloadOf } from "./action-creator-CQlFgQm4.js";
1
+ import { R as EventMap, U as Task, V as PayloadOf } from "./action-creator-HFA_LZOH.js";
2
2
  //#region src/policies/with-policy.d.ts
3
3
  /** What `withPolicy` returns: the task as a plain function that can be cancelled. */
4
4
  type PolicyFunction<P, R> = {
package/docs/package.md CHANGED
@@ -11,10 +11,10 @@ Imports are split so you only load what you use. `createBus` stays small; the re
11
11
  | `nanoeffects/match` | `matchPlugin`: `on`, `once` and `off` that take a function which picks the events |
12
12
  | `nanoeffects/context` | `contextPlugin`: your own fields (a store, a client) on `ctx` of every task, typed from the value |
13
13
  | `nanoeffects/signal` | `signalPlugin`: `emit(call, { signal })` ties the tasks of an emit to an outside `AbortSignal` |
14
- | `nanoeffects/oop` | `extendBus`, `WithBus`, `On`, `Once`, `disposeBus`: the methods of a bus on a class, with the subscriptions of each instance ended by `dispose()` |
14
+ | `nanoeffects/oop` | `Emitter`, `extendBus`, `WithBus`, `On`, `Once`, `disposeBus`: the methods of a bus on a class, with the subscriptions of each instance ended by `dispose()` |
15
15
  | `nanoeffects/scope` | `scopePlugin`, `effect`: fields for one command, action, job, module or `emit` (the types `Scope`, `Effect`) |
16
16
  | `nanoeffects/redux` | `createEffectsMiddleware` |
17
- | `nanoeffects/observable` | `createObserve` |
17
+ | `nanoeffects/observable` | `createObserve`, `Subject` |
18
18
  | `nanoeffects/react` | `reactPlugin`: adds the `useEmitter` hook to a bus (needs React 18 or newer) |
19
19
  | `nanoeffects/dev` | `devPlugin` (no-op in production) |
20
20
  | `nanoeffects/trace` | `createTracer`, the loggers and `tracePlugin` (names for the trace) |
@@ -0,0 +1,69 @@
1
+ # Start a project from a template
2
+
3
+ Use this page when you want a running project in one command instead of wiring Vite and the bus by hand. It makes a small app with a search box that waits for you to stop typing (`debounce`) and aborts the older request when a newer one starts (`latest`).
4
+
5
+ You need Node 18 or newer.
6
+
7
+ ## Create the project
8
+
9
+ Run the command for your package manager. Replace `my-app` with the name of the new directory.
10
+
11
+ ```bash
12
+ npm create nanoeffects@latest my-app
13
+ ```
14
+
15
+ ```bash
16
+ pnpm create nanoeffects my-app
17
+ ```
18
+
19
+ ```bash
20
+ yarn create nanoeffects my-app
21
+ ```
22
+
23
+ ```bash
24
+ bun create nanoeffects my-app
25
+ ```
26
+
27
+ The command asks for the template when you do not give one. The directory must be new or empty: the command stops instead of overwriting files.
28
+
29
+ Then follow the steps it prints:
30
+
31
+ ```bash
32
+ cd my-app
33
+ npm install
34
+ npm run dev
35
+ ```
36
+
37
+ Open the address that Vite prints and type in the box. The fake server answers after 800 ms, so you can see the older request being aborted.
38
+
39
+ ## Choose a template
40
+
41
+ Pass `--template` to skip the question. With npm, put `--` before the option.
42
+
43
+ | Template | What it shows | Use it when |
44
+ | -------- | ------------- | ----------- |
45
+ | `vanilla` | A bus, one event and a `debounce` plus `latest` handler, with plain DOM code | You use no framework, or want to see the bus alone |
46
+ | `react` | The same handler with `useEmitter`, and `usePolicy` for a debounced save in a component | You build a React app |
47
+
48
+ ```bash
49
+ npm create nanoeffects@latest my-app -- --template react
50
+ ```
51
+
52
+ ## Read the files
53
+
54
+ Both templates split the code the way [the guide](guide.md) does: one job per file.
55
+
56
+ | File | Job |
57
+ | ---- | --- |
58
+ | `src/bus.js` | Creates the bus. It imports no events. |
59
+ | `src/search.js` | Names the events with `createAction`. It imports no bus. |
60
+ | `src/search-handlers.js` | Handles the events with `debounce` and `latest`. It knows the bus and the events. |
61
+ | `src/api.js` | A fake server. Replace it with your own requests. |
62
+
63
+ Every call of nanoeffects in these files has a comment that says what it does. To make it your own, replace `src/api.js`, then rename the events and the handler.
64
+
65
+ ## Next steps
66
+
67
+ - [Policies](policies.md): `leading`, `throttle` and `queue` next to `latest`.
68
+ - [Build a sign-up form in React](react.md): the same ideas in a bigger React example.
69
+ - [Package entries](package.md): which import holds what.
package/docs/tracing.md CHANGED
@@ -314,7 +314,7 @@ With two quick `search` emits and a `latest` handler, the default list is `searc
314
314
  ### Write your own logger
315
315
 
316
316
  ```ts
317
- import type { TraceLogger } from "nanoeffects";
317
+ import type { TraceLogger } from "nanoeffects/trace";
318
318
 
319
319
  const errorsOnly = (): TraceLogger => (event) => {
320
320
  if (event.phase === "error") {
package/llms-full.txt CHANGED
@@ -500,6 +500,79 @@ More in [Errors](errors.md).
500
500
  | Guarantees | [Semantics](semantics.md) |
501
501
  | Which import | [Package entries](package.md) |
502
502
 
503
+ ---
504
+ Source: docs/starter.md
505
+
506
+ # Start a project from a template
507
+
508
+ Use this page when you want a running project in one command instead of wiring Vite and the bus by hand. It makes a small app with a search box that waits for you to stop typing (`debounce`) and aborts the older request when a newer one starts (`latest`).
509
+
510
+ You need Node 18 or newer.
511
+
512
+ ## Create the project
513
+
514
+ Run the command for your package manager. Replace `my-app` with the name of the new directory.
515
+
516
+ ```bash
517
+ npm create nanoeffects@latest my-app
518
+ ```
519
+
520
+ ```bash
521
+ pnpm create nanoeffects my-app
522
+ ```
523
+
524
+ ```bash
525
+ yarn create nanoeffects my-app
526
+ ```
527
+
528
+ ```bash
529
+ bun create nanoeffects my-app
530
+ ```
531
+
532
+ The command asks for the template when you do not give one. The directory must be new or empty: the command stops instead of overwriting files.
533
+
534
+ Then follow the steps it prints:
535
+
536
+ ```bash
537
+ cd my-app
538
+ npm install
539
+ npm run dev
540
+ ```
541
+
542
+ Open the address that Vite prints and type in the box. The fake server answers after 800 ms, so you can see the older request being aborted.
543
+
544
+ ## Choose a template
545
+
546
+ Pass `--template` to skip the question. With npm, put `--` before the option.
547
+
548
+ | Template | What it shows | Use it when |
549
+ | -------- | ------------- | ----------- |
550
+ | `vanilla` | A bus, one event and a `debounce` plus `latest` handler, with plain DOM code | You use no framework, or want to see the bus alone |
551
+ | `react` | The same handler with `useEmitter`, and `usePolicy` for a debounced save in a component | You build a React app |
552
+
553
+ ```bash
554
+ npm create nanoeffects@latest my-app -- --template react
555
+ ```
556
+
557
+ ## Read the files
558
+
559
+ Both templates split the code the way [the guide](guide.md) does: one job per file.
560
+
561
+ | File | Job |
562
+ | ---- | --- |
563
+ | `src/bus.js` | Creates the bus. It imports no events. |
564
+ | `src/search.js` | Names the events with `createAction`. It imports no bus. |
565
+ | `src/search-handlers.js` | Handles the events with `debounce` and `latest`. It knows the bus and the events. |
566
+ | `src/api.js` | A fake server. Replace it with your own requests. |
567
+
568
+ Every call of nanoeffects in these files has a comment that says what it does. To make it your own, replace `src/api.js`, then rename the events and the handler.
569
+
570
+ ## Next steps
571
+
572
+ - [Policies](policies.md): `leading`, `throttle` and `queue` next to `latest`.
573
+ - [Build a sign-up form in React](react.md): the same ideas in a bigger React example.
574
+ - [Package entries](package.md): which import holds what.
575
+
503
576
  ---
504
577
  Source: docs/motivation.md
505
578
 
@@ -561,10 +634,10 @@ Imports are split so you only load what you use. `createBus` stays small; the re
561
634
  | `nanoeffects/match` | `matchPlugin`: `on`, `once` and `off` that take a function which picks the events |
562
635
  | `nanoeffects/context` | `contextPlugin`: your own fields (a store, a client) on `ctx` of every task, typed from the value |
563
636
  | `nanoeffects/signal` | `signalPlugin`: `emit(call, { signal })` ties the tasks of an emit to an outside `AbortSignal` |
564
- | `nanoeffects/oop` | `extendBus`, `WithBus`, `On`, `Once`, `disposeBus`: the methods of a bus on a class, with the subscriptions of each instance ended by `dispose()` |
637
+ | `nanoeffects/oop` | `Emitter`, `extendBus`, `WithBus`, `On`, `Once`, `disposeBus`: the methods of a bus on a class, with the subscriptions of each instance ended by `dispose()` |
565
638
  | `nanoeffects/scope` | `scopePlugin`, `effect`: fields for one command, action, job, module or `emit` (the types `Scope`, `Effect`) |
566
639
  | `nanoeffects/redux` | `createEffectsMiddleware` |
567
- | `nanoeffects/observable` | `createObserve` |
640
+ | `nanoeffects/observable` | `createObserve`, `Subject` |
568
641
  | `nanoeffects/react` | `reactPlugin`: adds the `useEmitter` hook to a bus (needs React 18 or newer) |
569
642
  | `nanoeffects/dev` | `devPlugin` (no-op in production) |
570
643
  | `nanoeffects/trace` | `createTracer`, the loggers and `tracePlugin` (names for the trace) |
@@ -4998,7 +5071,7 @@ With two quick `search` emits and a `latest` handler, the default list is `searc
4998
5071
  ### Write your own logger
4999
5072
 
5000
5073
  ```ts
5001
- import type { TraceLogger } from "nanoeffects";
5074
+ import type { TraceLogger } from "nanoeffects/trace";
5002
5075
 
5003
5076
  const errorsOnly = (): TraceLogger => (event) => {
5004
5077
  if (event.phase === "error") {
package/llms.txt CHANGED
@@ -15,6 +15,7 @@ Rules that generated code often gets wrong:
15
15
  ## Start here
16
16
 
17
17
  - [Guide](docs/guide.md): bus, handler context, policies, effects, commands and modules, step by step
18
+ - [Start a project from a template](docs/starter.md): `npm create nanoeffects` makes a Vite project (`vanilla` or `react`) with a bus, `debounce` and `latest`
18
19
  - [Why nanoeffects exists](docs/motivation.md): no dependencies and no global state for SDKs and Module Federation, and why not Redux, Effector or RxJS
19
20
  - [Package entries](docs/package.md): which import holds what
20
21
  - [Plugins](docs/plugins.md): every plugin of a bus, what `bus.use` returns, and the order to use them in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoeffects",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Cancel stale async work and fix race conditions in event handlers: a typed event bus where every handler is a task with an AbortSignal, plus latest, debounce, throttle, queue, retry, timeout and poll. About 1.4 kB gzip.",
5
5
  "keywords": [
6
6
  "event-bus",
@@ -138,13 +138,13 @@
138
138
  "scripts": {
139
139
  "build": "tsdown && node scripts/notrace-types.mjs && node scripts/llms-full.mjs",
140
140
  "prepublishOnly": "pnpm build",
141
- "check": "biome check ./src ./examples ./integration ./scripts",
142
- "format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts",
141
+ "check": "biome check ./src ./examples ./integration ./scripts ./packages",
142
+ "format": "npx @biomejs/biome check --write --unsafe ./src ./examples ./integration ./scripts ./packages",
143
143
  "tsgo": "tsc --noEmit",
144
144
  "test": "vitest run",
145
145
  "test:watch": "vitest",
146
146
  "prepare": "lefthook install",
147
- "lint:package": "publint && attw --pack . --profile esm-only",
147
+ "lint:package": "publint && attw --pack . --profile esm-only && publint packages/create-nanoeffects",
148
148
  "size": "size-limit",
149
149
  "verify": "pnpm tsgo && pnpm check && pnpm docs:check && pnpm llms:check && pnpm test && pnpm build && pnpm test:integration && pnpm smoke && pnpm lint:package && pnpm size",
150
150
  "test:integration": "vitest run --config vitest.integration.config.ts",
@@ -163,6 +163,7 @@
163
163
  "@size-limit/file": "^14.2.0",
164
164
  "@types/react": "^19.3.0",
165
165
  "@types/react-dom": "^19.3.0",
166
+ "@vitejs/plugin-react": "^6.1.2",
166
167
  "archunit": "^2.5.4",
167
168
  "happy-dom": "^21.0.4",
168
169
  "jotai": "^3.0.1",
@@ -1 +0,0 @@
1
- import{d as e,n as t,o as n,r}from"./context-CJGW6OWj.js";import{n as i}from"./promise-CSLpzwSR.js";import{n as a,t as o}from"./event-0RIBGYqS.js";const s=`*`,c=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},l=Symbol(),u=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,l,{value:e,enumerable:!1}),r},d=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&l in e)return e[l]},f=(e,t,n)=>Reflect.apply(e,null,[t,n]),p=(s={})=>{let l=c(),u=(e,t)=>l.add(o(e),t),p=(e,t)=>{let n=u(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(o(e),t)},h=(n,a)=>{let{onError:o}=s,{ctx:c}=t({event:a,bus:g,tracer:s.trace,parent:{ref:r()}});if(!o){n(a.payload,c);return}let l=t=>{try{o(t,a)}catch(t){e(`onError failed`,t)}};try{let e=n(a.payload,c);i(e)&&Promise.resolve(e).catch(l)}catch(e){l(e)}},g={on:u,once:p,off:m,emit:(e,i)=>{let c=o(e),u=a(e,i),p={type:c,payload:u},m=d(e),_=[...l.get(c),...l.get(`*`)];_.length===0&&!m&&s.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:e}=t({event:p,bus:g,tracer:s.trace,parent:{ref:r()}}),i=g.commands?.run??f;return n(e,`command`,()=>i(m,u,e))}},use:e=>e(g),ctx:s.context,trace:s.trace};return g};export{s as a,u as i,d as n,p as r,l as t};
@@ -1,14 +0,0 @@
1
- import { B as EventMap, x as ContextOf } from "./action-creator-CQlFgQm4.js";
2
- //#region src/core/context-types.d.ts
3
- /** What a function that makes the fields of a task gets to see. */
4
- type ContextTask = {
5
- type: string;
6
- payload?: unknown;
7
- };
8
- /**
9
- * `unknown` when none of the `fields` is already a context field of the bus,
10
- * else `never`: the call does not compile. Used as `bus: Bus<E> & NoClash<…>`.
11
- */
12
- type NoClash<Fields extends object, E extends EventMap> = [keyof Fields & keyof ContextOf<E>] extends [never] ? unknown : never;
13
- //#endregion
14
- export { NoClash as n, ContextTask as t };
@@ -1 +0,0 @@
1
- import{a as e,l as t,n,r}from"./context-yYU3_9lq.js";import{n as i}from"./promise-CSLpzwSR.js";const a=e=>typeof e==`string`?e:e.type,o=(e,t)=>typeof e==`object`?e.payload:t,s=`*`,c=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},l=Symbol(),u=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,l,{value:e,enumerable:!1}),r},d=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&l in e)return e[l]},f=(e,t,n)=>Reflect.apply(e,null,[t,n]),p=(s={})=>{let l=c(),u=(e,t)=>l.add(a(e),t),p=(e,t)=>{let n=u(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(a(e),t)},h=(e,a)=>{let{onError:o}=s,{ctx:c}=n({event:a,bus:g,tracer:s.trace,parent:{ref:r()}});if(!o){e(a.payload,c);return}let l=e=>{try{o(e,a)}catch(e){t(`onError failed`,e)}};try{let t=e(a.payload,c);i(t)&&Promise.resolve(t).catch(l)}catch(e){l(e)}},g={on:u,once:p,off:m,emit:(t,i)=>{let c=a(t),u=o(t,i),p={type:c,payload:u},m=d(t),_=[...l.get(c),...l.get(`*`)];_.length===0&&!m&&s.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:t}=n({event:p,bus:g,tracer:s.trace,parent:{ref:r()}}),i=g.commands?.run??f;return e(t,`command`,()=>i(m,u,t))}},use:e=>e(g),ctx:s.context,trace:s.trace};return g};export{a,s as i,p as n,u as r,l as t};