nanoeffects 0.19.1 → 0.20.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 (46) hide show
  1. package/dist/{action-creator-HFA_LZOH.d.ts → action-creator-Bpa8BUS9.d.ts} +18 -7
  2. package/dist/actions.d.ts +3 -3
  3. package/dist/actions.js +1 -1
  4. package/dist/{context-types-BNcs43eY.d.ts → context-types-BKIH5a8s.d.ts} +1 -1
  5. package/dist/context.d.ts +2 -2
  6. package/dist/dev.d.ts +2 -2
  7. package/dist/dev.js +1 -1
  8. package/dist/effects.d.ts +4 -8
  9. package/dist/index.d.ts +2 -2
  10. package/dist/match.d.ts +1 -1
  11. package/dist/{module-DTf73Wdq.d.ts → module-B0KVDNjY.d.ts} +14 -9
  12. package/dist/mount-each-D54UqAhZ.js +1 -0
  13. package/dist/notrace/{action-creator-CbFf398i.d.ts → action-creator-D2CotugT.d.ts} +16 -7
  14. package/dist/notrace/actions.d.ts +14 -9
  15. package/dist/notrace/actions.js +1 -1
  16. package/dist/notrace/effects.d.ts +4 -8
  17. package/dist/notrace/index.d.ts +2 -2
  18. package/dist/notrace/{plugin-C5vIjxhR.d.ts → plugin-C6KA4dX-.d.ts} +1 -1
  19. package/dist/notrace/policies.d.ts +1 -1
  20. package/dist/notrace/redux.d.ts +1 -1
  21. package/dist/observable.d.ts +1 -1
  22. package/dist/oop.d.ts +1 -1
  23. package/dist/{plugin-Sy8z9IId.d.ts → plugin-D9UTzGRG.d.ts} +2 -2
  24. package/dist/policies.d.ts +2 -2
  25. package/dist/react.d.ts +3 -4
  26. package/dist/redux.d.ts +1 -1
  27. package/dist/scope.d.ts +4 -4
  28. package/dist/signal.d.ts +1 -1
  29. package/dist/state-of-C19H6BoV.d.ts +10 -0
  30. package/dist/trace.d.ts +1 -1
  31. package/dist/{types-DaZT158m.d.ts → types-CbdJKC2z.d.ts} +2 -2
  32. package/dist/vue.d.ts +72 -0
  33. package/dist/vue.js +1 -0
  34. package/dist/{with-policy-C_mX7S54.d.ts → with-policy-BeH8wCkX.d.ts} +1 -1
  35. package/docs/README.md +2 -0
  36. package/docs/actions.md +31 -1
  37. package/docs/chat-example.md +241 -0
  38. package/docs/migrating-from-rxjs.md +58 -1
  39. package/docs/package.md +1 -0
  40. package/docs/plugins.md +3 -3
  41. package/docs/starter.md +14 -1
  42. package/docs/typescript.md +14 -0
  43. package/docs/vue.md +96 -0
  44. package/llms-full.txt +467 -7
  45. package/llms.txt +4 -2
  46. package/package.json +23 -3
@@ -75,6 +75,19 @@ type EventPayload<E extends EventMap> = E[EventKey<E>];
75
75
  type WithType<K extends string> = {
76
76
  type: K;
77
77
  };
78
+ /**
79
+ * An object that has the `signal` of a task: the context of a task, `{ signal }`, or the
80
+ * `{ signal, abort }` that a starter of `all` and `race` gets. A function that only needs to
81
+ * stop its request when the task is aborted takes `WithSignal`:
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const search = (query: string, { signal }: WithSignal) => fetch(`/search?q=${query}`, { signal });
86
+ * ```
87
+ */
88
+ type WithSignal = {
89
+ signal: AbortSignal;
90
+ };
78
91
  type HandlerRef<E extends EventMap, Response = unknown> = (action: Action<E>) => Response;
79
92
  type Handler<E extends EventMap, Response = unknown, K extends EventKey<E> = EventKey<E>> = { [P in K]: {
80
93
  type: P;
@@ -278,12 +291,10 @@ type BusOptions<E extends EventMap> = {
278
291
  declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
279
292
  //#endregion
280
293
  //#region src/core/effect-types.d.ts
281
- /** What an effect needs of the task it runs for: its signal. A task context fits, and so does `{ signal }`. */
282
- type Signaled = {
283
- signal: AbortSignal;
284
- };
294
+ /** What an effect needs of the task it runs for: its signal. The name `WithSignal` is the one to use; this one stays for `nanoeffects/scope`. */
295
+ type Signaled = WithSignal;
285
296
  /** An effect: a function whose first parameter takes `{ signal }`, like `retry(ctx, fn)`. */
286
- type SignalFirst = (ctx: Signaled, ...args: never[]) => unknown;
297
+ type SignalFirst = (ctx: WithSignal, ...args: never[]) => unknown;
287
298
  /** The effects of a scope or of `effectsPlugin`, by the name they get on the context. */
288
299
  type Effects = Record<string, SignalFirst>;
289
300
  declare const bound: unique symbol;
@@ -299,7 +310,7 @@ declare const bound: unique symbol;
299
310
  * const first: Effect<First> = (ctx, items) => items[0];
300
311
  * ```
301
312
  */
302
- type Effect<F extends (...args: never[]) => unknown> = ((ctx: Signaled, ...args: Parameters<F>) => ReturnType<F>) & {
313
+ type Effect<F extends (...args: never[]) => unknown> = ((ctx: WithSignal, ...args: Parameters<F>) => ReturnType<F>) & {
303
314
  readonly [bound]?: F;
304
315
  };
305
316
  /** The bound form of a plain effect: the first parameter is gone, and so are its generics. */
@@ -400,4 +411,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
400
411
  toString(): T;
401
412
  }
402
413
  //#endregion
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 };
414
+ export { HandlerRef as A, Keys as B, Emit as C, EventPayload as D, EventLike as E, WithType as F, Trace as G, PayloadOf as H, createBus as I, UnsubscribeCallback as J, TraceEvent as K, Tracer as L, On as M, WithContext as N, EventsOf as O, WithSignal as P, EffectName as R, ContextOption as S, EventKey as T, Phase as U, ListenerOptions as V, Task 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, TraceLogger 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, EventMap as z };
package/dist/actions.d.ts CHANGED
@@ -1,6 +1,6 @@
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";
1
+ import { H as PayloadOf, T as EventKey, W as Task, c as WithScope, h as Bus, n as Free, o as Scope, r as FreeActionCreator, t as ActionCreator, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { r as Scoped, t as FieldsOfScope } from "./types-CbdJKC2z.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-B0KVDNjY.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{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};
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";import{t as d}from"./mount-each-D54UqAhZ.js";const f=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),p=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),m=e=>Reflect.get(e,u);function h(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(f((...t)=>f({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var g=class extends Error{};function _(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new g(`No handler for command "${e}"`);return t(r,i)}return f(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=f(a,n);return s}const v=(e,t)=>[e,t],y=e=>typeof Reflect.get(e??{},`handle`)==`function`,b=(e=[])=>t=>{let n=t.commands;if(y(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},x=()=>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})},S=e=>typeof e==`string`?h(e):e,C=(e,t,n,r)=>{let i=m(t);e.emit(Reflect.apply(t,null,[n]),r&&i?p(r,i):r)},w=(t,r,i,a)=>{let o=t;o[n]=!0;try{C(t,r,i,a)}catch(t){e(`cancel listener`,t)}o[n]=!1},T=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof g)throw e;return Promise.reject(e)}},E=(t,n,r={},a)=>{let l=_(t,n),u=e=>S(r[e]??`${t}/${e}`),d=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),g=(t,n,r,o)=>{let s=r,l=`idle`,u=()=>{},f=()=>{l=`closed`,u()},g=e=>{l===`started`&&(f(),w(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=i(s,g),C(s,d,n,a))},v=e=>{l===`started`&&(f(),s.signal.aborted?w(s,h,s.signal.reason,a):`error`in e?C(s,m,e.error,a):C(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),T(()=>(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)=>g(e,n,r,t)};function y(e,r){return typeof r==`object`?n?g(l,e,r,!1):Reflect.apply(l,null,[e,r]):f(o(x,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:d,success:p,fail:m,cancel:h}),x=f(b,a);return x},D=e=>typeof e==`object`&&!!e,O=e=>{if(typeof e==`string`)return e;if(D(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},k=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(O(n),O(t[0]))&&(r===void 0||Object.is(r,t[1]))},A=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`&&k(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 j(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const M=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,N=(e,t,n)=>{n&&e.applyScope?.(t,n)},P=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],F=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},I=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},L=(n=[])=>a=>{let o=a.commands??b()(a),s={handle:(...e)=>{if(!o.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(o.handle,null,e)}},c=e=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;return{mount:o=>{let l=n.get(o);if(l)return l;let u=r.get(o.name);u&&n.get(u)?.();let d=t(e,o.name),f=d.ctx,p=c(f),m=()=>{n.delete(o),r.get(o.name)===o&&r.delete(o.name),f.abort(),d.unlink()};n.set(o,m),r.set(o.name,o);let h=o.scope,g=M(a,h),_=(e,t)=>{let n=Reflect.apply(s.handle,null,P(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=I(f),b=F(f,g);try{N(a,f,h),o.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>n.get(e)?.(),isMounted:e=>n.has(e)}},l=A(a),u=a.emit,f,p=(e=!0)=>{if(f)return f;l.release(),a.emit===m&&(a.emit=u);let t=r({event:{type:`app`,payload:void 0},bus:a,tracer:a.trace});f={root:t,apps:d(c(t.ctx))};try{e&&f.apps.mount(...n)}finally{l.replay()}return f},m=(...e)=>(p(),Reflect.apply(u,a,e));a.emit=m,n.length>0&&queueMicrotask(()=>{try{p()}catch(t){e(`the modules of the app could not start`,t)}});let h={get commands(){return p(),o},mount:(...e)=>{let{root:t,apps:n}=p();return t.ctx.signal.throwIfAborted(),n.mount(...e)},unmount:(...e)=>p().apps.unmount(...e),isMounted:e=>p().apps.isMounted(e),dispose:()=>p(!1).root.ctx.abort(),createModule:j};return a.app=h,h};export{v as bindHandler,b as commandsPlugin,h as createAction,_ as createCommand,E as createJob,j as createModule,x as emitterPlugin,L as modulePlugin};
@@ -1,4 +1,4 @@
1
- import { R as EventMap, x as ContextOf } from "./action-creator-HFA_LZOH.js";
1
+ import { x as ContextOf, z as EventMap } from "./action-creator-Bpa8BUS9.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 { 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";
1
+ import { N as WithContext, h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { n as NoClash, t as ContextTask } from "./context-types-BKIH5a8s.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 { 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";
1
+ import { J as UnsubscribeCallback, h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { i as WithApp, n as ModuleApi } from "./module-B0KVDNjY.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/dev.js CHANGED
@@ -1 +1 @@
1
- import{t as e}from"./event-0RIBGYqS.js";const t=`[nanoeffects]`,n=(e={})=>t=>{let{maxListeners:n=10,leaks:r=!0,modules:o=!0,app:s}=e,c=e.log??(e=>console.warn(e)),l=e.log??(e=>console.info(e)),u=[];return r&&u.push(i(t,n,c)),o&&u.push(a(t,s,l)),()=>{for(let e of u.splice(0))e()}},r=t=>typeof t==`function`&&typeof Reflect.get(t,`type`)!=`string`?`*`:e(t),i=(e,n,i)=>{let a=e.on,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=!0,l=(...l)=>{if(!c)return Reflect.apply(a,e,l);let[u]=l,d=r(u),f=(o.get(d)??0)+1;o.set(d,f),f>n&&!s.has(d)&&(s.add(d),i(`${t} ${f} listeners of "${d}" were added and not unsubscribed (more than ${n}). A file that is reloaded and subscribes again, or an unsubscribe that is never called?`));let p=Reflect.apply(a,e,l),m=!1;return()=>{if(!m){m=!0;let e=(o.get(d)??1)-1;o.set(d,e),e<=n&&s.delete(d)}p()}};return e.on=l,()=>{c=!1,e.on===l&&(e.on=a)}},a=(e,t,n)=>{let r=t??e.app;if(r)return o(r,n);let i,a;return Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,get:()=>i,set:e=>{a?.(),i=e,a=e?o(e,n):void 0}}),()=>{a?.(),Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,writable:!0,value:i})}},o=(e,n)=>{let{mount:r,unmount:i}=e,a=/* @__PURE__ */ new Map;return e.mount=i=>{let o=a.get(i.name);if(o===i&&e.isMounted(i))return r(i);let s=o!==void 0&&e.isMounted(o),c=r(i);return a.set(i.name,i),n(`${t} module "${i.name}" ${s?`replaced`:`mounted`}`),()=>{e.isMounted(i)&&n(`${t} module "${i.name}" unmounted`),c()}},e.unmount=r=>{e.isMounted(r)&&n(`${t} module "${r.name}" unmounted`),i(r)},()=>{e.mount=r,e.unmount=i}};export{n as devPlugin};
1
+ import{t as e}from"./event-0RIBGYqS.js";import{t}from"./mount-each-D54UqAhZ.js";const n=`[nanoeffects]`,r=(e={})=>t=>{let{maxListeners:n=10,leaks:r=!0,modules:i=!0,app:s}=e,c=e.log??(e=>console.warn(e)),l=e.log??(e=>console.info(e)),u=[];return r&&u.push(a(t,n,c)),i&&u.push(o(t,s,l)),()=>{for(let e of u.splice(0))e()}},i=t=>typeof t==`function`&&typeof Reflect.get(t,`type`)!=`string`?`*`:e(t),a=(e,t,r)=>{let a=e.on,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=!0,l=(...l)=>{if(!c)return Reflect.apply(a,e,l);let[u]=l,d=i(u),f=(o.get(d)??0)+1;o.set(d,f),f>t&&!s.has(d)&&(s.add(d),r(`${n} ${f} listeners of "${d}" were added and not unsubscribed (more than ${t}). A file that is reloaded and subscribes again, or an unsubscribe that is never called?`));let p=Reflect.apply(a,e,l),m=!1;return()=>{if(!m){m=!0;let e=(o.get(d)??1)-1;o.set(d,e),e<=t&&s.delete(d)}p()}};return e.on=l,()=>{c=!1,e.on===l&&(e.on=a)}},o=(e,t,n)=>{let r=t??e.app;if(r)return s(r,n);let i,a;return Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,get:()=>i,set:e=>{a?.(),i=e,a=e?s(e,n):void 0}}),()=>{a?.(),Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,writable:!0,value:i})}},s=(e,r)=>{let{mount:i,unmount:a}=e,o=/* @__PURE__ */ new Map,s=t({mount:t=>{let a=o.get(t.name);if(a===t&&e.isMounted(t))return i(t);let s=a!==void 0&&e.isMounted(a),c=i(t);return o.set(t.name,t),r(`${n} module "${t.name}" ${s?`replaced`:`mounted`}`),()=>{e.isMounted(t)&&r(`${n} module "${t.name}" unmounted`),c()}},unmount:t=>{e.isMounted(t)&&r(`${n} module "${t.name}" unmounted`),a(t)},isMounted:t=>e.isMounted(t)});return e.mount=s.mount,e.unmount=s.unmount,()=>{e.mount=i,e.unmount=a}};export{r as devPlugin};
package/dist/effects.d.ts CHANGED
@@ -1,5 +1,5 @@
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";
1
+ import { P as WithSignal, W as Task, u as Effect, z as EventMap } from "./action-creator-Bpa8BUS9.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-D9UTzGRG.js";
3
3
  //#region src/utils/onAbort.d.ts
4
4
  export declare const onAbort: (ctx: {
5
5
  signal?: AbortSignal | undefined;
@@ -66,9 +66,7 @@ type CancellableExecutor<T> = (handle: CancellableHandle<T>) => void;
66
66
  * );
67
67
  * ```
68
68
  */
69
- export declare const cancellable: <T = void>(ctx: {
70
- signal: AbortSignal;
71
- }, executor: CancellableExecutor<T>) => Promise<T>;
69
+ export declare const cancellable: <T = void>(ctx: WithSignal, executor: CancellableExecutor<T>) => Promise<T>;
72
70
  //#endregion
73
71
  //#region src/effects/poll.d.ts
74
72
  type PollOptions = {
@@ -108,9 +106,7 @@ type PollOptions = {
108
106
  */
109
107
  type PollMs = number | ((call: number) => number);
110
108
  export declare function poll<P, E extends EventMap, R>(ms: PollMs, task: Task<P, E, R>, options?: PollOptions): Task<P, E, Promise<void>>;
111
- export declare function poll(ctx: {
112
- signal: AbortSignal;
113
- }, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
109
+ export declare function poll(ctx: WithSignal, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
114
110
  //#endregion
115
111
  //#region src/effects/retry.d.ts
116
112
  type RetryOptions = {
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
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 };
1
+ import { A as HandlerRef, B as Keys, C as Emit, D as EventPayload, E as EventLike, F as WithType, H as PayloadOf, I as createBus, J as UnsubscribeCallback, M as On, N as WithContext, O as EventsOf, P as WithSignal, S as ContextOption, T as EventKey, W as Task, _ 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, v as CommandCall, w as Emittable, x as ContextOf, y as Commands, z as EventMap } from "./action-creator-Bpa8BUS9.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 WithSignal, type WithType, createBus };
package/dist/match.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { D as EventPayload, J as UnsubscribeCallback, W as Task, h as Bus, p as Action, z as EventMap } from "./action-creator-Bpa8BUS9.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 { 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";
1
+ import { H as PayloadOf, J as UnsubscribeCallback, W as Task, _ as Command, b as Context, c as WithScope, h as Bus, o as Scope, v as CommandCall, y as Commands, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-CbdJKC2z.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> & {
@@ -159,12 +159,12 @@ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<
159
159
  * of what `modulePlugin` returns that `devPlugin` wraps.
160
160
  */
161
161
  interface ModuleHost {
162
- mount(module: {
162
+ mount(...modules: Array<{
163
163
  readonly name: string;
164
- }): UnsubscribeCallback;
165
- unmount(module: {
164
+ }>): UnsubscribeCallback;
165
+ unmount(...modules: Array<{
166
166
  readonly name: string;
167
- }): void;
167
+ }>): void;
168
168
  isMounted(module: {
169
169
  readonly name: string;
170
170
  }): boolean;
@@ -177,9 +177,14 @@ interface WithApp {
177
177
  type ModuleApi<E extends EventMap = EventMap> = {
178
178
  /** The registry of command handlers of the bus: the one it was made with, or the app's own. */
179
179
  commands: Registry<E>;
180
- /** Mounts a module and returns the function that unmounts it; a module that is mounted already is not run again. */
181
- mount(module: Module<E>): UnsubscribeCallback;
182
- unmount(module: Module<E>): void;
180
+ /**
181
+ * Mounts modules, in the order given, and returns the function that unmounts them, last
182
+ * mounted first. A module that is mounted already is not run again. If one of them throws,
183
+ * the ones mounted by this call are unmounted and the error is thrown.
184
+ */
185
+ mount(...modules: Module<E>[]): UnsubscribeCallback;
186
+ /** Unmounts modules, in reverse order of the arguments. */
187
+ unmount(...modules: Module<E>[]): void;
183
188
  isMounted(module: Module<E>): boolean;
184
189
  /** Unmounts every module; a disposed app cannot mount modules. */
185
190
  dispose(): void;
@@ -0,0 +1 @@
1
+ const e=e=>({mount:(...t)=>{let[n]=t;if(t.length===1&&n!==void 0)return e.mount(n);let r=[],i=()=>{for(let e of r.splice(0).reverse())e()};try{for(let n of t)e.isMounted(n)||r.push(e.mount(n))}catch(e){throw i(),e}return i},unmount:(...t)=>{for(let n of[...t].reverse())e.unmount(n)},isMounted:e.isMounted});export{e as t};
@@ -53,6 +53,19 @@ type EventPayload<E extends EventMap> = E[EventKey<E>];
53
53
  type WithType<K extends string> = {
54
54
  type: K;
55
55
  };
56
+ /**
57
+ * An object that has the `signal` of a task: the context of a task, `{ signal }`, or the
58
+ * `{ signal, abort }` that a starter of `all` and `race` gets. A function that only needs to
59
+ * stop its request when the task is aborted takes `WithSignal`:
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const search = (query: string, { signal }: WithSignal) => fetch(`/search?q=${query}`, { signal });
64
+ * ```
65
+ */
66
+ type WithSignal = {
67
+ signal: AbortSignal;
68
+ };
56
69
  type HandlerRef<E extends EventMap, Response = unknown> = (action: Action<E>) => Response;
57
70
  type Handler<E extends EventMap, Response = unknown, K extends EventKey<E> = EventKey<E>> = { [P in K]: {
58
71
  type: P;
@@ -256,12 +269,8 @@ type BusOptions<E extends EventMap> = {
256
269
  declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
257
270
  //#endregion
258
271
  //#region src/core/effect-types.d.ts
259
- /** What an effect needs of the task it runs for: its signal. A task context fits, and so does `{ signal }`. */
260
- type Signaled = {
261
- signal: AbortSignal;
262
- };
263
272
  /** An effect: a function whose first parameter takes `{ signal }`, like `retry(ctx, fn)`. */
264
- type SignalFirst = (ctx: Signaled, ...args: never[]) => unknown;
273
+ type SignalFirst = (ctx: WithSignal, ...args: never[]) => unknown;
265
274
  /** The effects of a scope or of `effectsPlugin`, by the name they get on the context. */
266
275
  type Effects = Record<string, SignalFirst>;
267
276
  declare const bound: unique symbol;
@@ -277,7 +286,7 @@ declare const bound: unique symbol;
277
286
  * const first: Effect<First> = (ctx, items) => items[0];
278
287
  * ```
279
288
  */
280
- type Effect<F extends (...args: never[]) => unknown> = ((ctx: Signaled, ...args: Parameters<F>) => ReturnType<F>) & {
289
+ type Effect<F extends (...args: never[]) => unknown> = ((ctx: WithSignal, ...args: Parameters<F>) => ReturnType<F>) & {
281
290
  readonly [bound]?: F;
282
291
  };
283
292
  /** The bound form of a plain effect: the first parameter is gone, and so are its generics. */
@@ -378,4 +387,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
378
387
  toString(): T;
379
388
  }
380
389
  //#endregion
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 };
390
+ export { On as A, EventKey as C, Handler as D, EventsOf as E, EventMap as F, Keys as I, PayloadOf as L, WithSignal as M, WithType as N, HandlerRef as O, createBus as P, Task 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, UnsubscribeCallback as z };
@@ -1,5 +1,5 @@
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";
1
+ import { C as EventKey, F as EventMap, L as PayloadOf, R as Task, _ 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, z as UnsubscribeCallback } from "./action-creator-D2CotugT.js";
2
+ import { t as BoundOf } from "./plugin-C6KA4dX-.js";
3
3
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
4
4
  //#region src/scope/types.d.ts
5
5
  /**
@@ -341,12 +341,12 @@ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<
341
341
  * of what `modulePlugin` returns that `devPlugin` wraps.
342
342
  */
343
343
  interface ModuleHost {
344
- mount(module: {
344
+ mount(...modules: Array<{
345
345
  readonly name: string;
346
- }): UnsubscribeCallback;
347
- unmount(module: {
346
+ }>): UnsubscribeCallback;
347
+ unmount(...modules: Array<{
348
348
  readonly name: string;
349
- }): void;
349
+ }>): void;
350
350
  isMounted(module: {
351
351
  readonly name: string;
352
352
  }): boolean;
@@ -359,9 +359,14 @@ interface WithApp {
359
359
  type ModuleApi<E extends EventMap = EventMap> = {
360
360
  /** The registry of command handlers of the bus: the one it was made with, or the app's own. */
361
361
  commands: Registry<E>;
362
- /** Mounts a module and returns the function that unmounts it; a module that is mounted already is not run again. */
363
- mount(module: Module<E>): UnsubscribeCallback;
364
- unmount(module: Module<E>): void;
362
+ /**
363
+ * Mounts modules, in the order given, and returns the function that unmounts them, last
364
+ * mounted first. A module that is mounted already is not run again. If one of them throws,
365
+ * the ones mounted by this call are unmounted and the error is thrown.
366
+ */
367
+ mount(...modules: Module<E>[]): UnsubscribeCallback;
368
+ /** Unmounts modules, in reverse order of the arguments. */
369
+ unmount(...modules: Module<E>[]): void;
365
370
  isMounted(module: Module<E>): boolean;
366
371
  /** Unmounts every module; a disposed app cannot mount modules. */
367
372
  dispose(): void;
@@ -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{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};
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)}}}}},A=e=>({mount:(...t)=>{let[n]=t;if(t.length===1&&n!==void 0)return e.mount(n);let r=[],i=()=>{for(let e of r.splice(0).reverse())e()};try{for(let n of t)e.isMounted(n)||r.push(e.mount(n))}catch(e){throw i(),e}return i},unmount:(...t)=>{for(let n of[...t].reverse())e.unmount(n)},isMounted:e.isMounted});function j(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const M=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,N=(e,t,n)=>{n&&e.applyScope?.(t,n)},P=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],F=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},I=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},L=(i=[])=>a=>{let o=a.commands??y()(a),s={handle:(...e)=>{if(!o.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(o.handle,null,e)}},c=n=>{let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return{mount:o=>{let l=r.get(o);if(l)return l;let u=i.get(o.name);u&&r.get(u)?.();let d=t(n,o.name),f=d.ctx,p=c(f),m=()=>{r.delete(o),i.get(o.name)===o&&i.delete(o.name),f.abort(),d.unlink()};r.set(o,m),i.set(o.name,o);let h=o.scope,g=M(a,h),_=(t,n)=>{let r=Reflect.apply(s.handle,null,P(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=I(f),b=F(f,g);try{N(a,f,h),o.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)}},l=k(a),u=a.emit,d,f=(e=!0)=>{if(d)return d;l.release(),a.emit===p&&(a.emit=u);let t=r({event:{type:`app`,payload:void 0},bus:a,tracer:a.trace});d={root:t,apps:A(c(t.ctx))};try{e&&d.apps.mount(...i)}finally{l.replay()}return d},p=(...e)=>(f(),Reflect.apply(u,a,e));a.emit=p,i.length>0&&queueMicrotask(()=>{try{f()}catch(e){n(`the modules of the app could not start`,e)}});let m={get commands(){return f(),o},mount:(...e)=>{let{root:t,apps:n}=f();return t.ctx.signal.throwIfAborted(),n.mount(...e)},unmount:(...e)=>f().apps.unmount(...e),isMounted:e=>f().apps.isMounted(e),dispose:()=>f(!1).root.ctx.abort(),createModule:j};return a.app=m,m};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,j as createModule,b as emitterPlugin,L as modulePlugin};
@@ -1,5 +1,5 @@
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";
1
+ import { F as EventMap, M as WithSignal, R as Task, l as Effect } from "./action-creator-D2CotugT.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-C6KA4dX-.js";
3
3
  //#region src/utils/onAbort.d.ts
4
4
  export declare const onAbort: (ctx: {
5
5
  signal?: AbortSignal | undefined;
@@ -66,9 +66,7 @@ type CancellableExecutor<T> = (handle: CancellableHandle<T>) => void;
66
66
  * );
67
67
  * ```
68
68
  */
69
- export declare const cancellable: <T = void>(ctx: {
70
- signal: AbortSignal;
71
- }, executor: CancellableExecutor<T>) => Promise<T>;
69
+ export declare const cancellable: <T = void>(ctx: WithSignal, executor: CancellableExecutor<T>) => Promise<T>;
72
70
  //#endregion
73
71
  //#region src/effects/poll.d.ts
74
72
  type PollOptions = {
@@ -108,9 +106,7 @@ type PollOptions = {
108
106
  */
109
107
  type PollMs = number | ((call: number) => number);
110
108
  export declare function poll<P, E extends EventMap, R>(ms: PollMs, task: Task<P, E, R>, options?: PollOptions): Task<P, E, Promise<void>>;
111
- export declare function poll(ctx: {
112
- signal: AbortSignal;
113
- }, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
109
+ export declare function poll(ctx: WithSignal, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
114
110
  //#endregion
115
111
  //#region src/effects/retry.d.ts
116
112
  type RetryOptions = {
@@ -1,2 +1,2 @@
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
+ import { A as On, C as EventKey, D as Handler, E as EventsOf, F as EventMap, I as Keys, L as PayloadOf, M as WithSignal, N as WithType, O as HandlerRef, P as createBus, R as Task, 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, z as UnsubscribeCallback } from "./action-creator-D2CotugT.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 WithSignal, type WithType, createBus };
@@ -1,4 +1,4 @@
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";
1
+ import { F as EventMap, I as Keys, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, y as ContextOf } from "./action-creator-D2CotugT.js";
2
2
  //#region src/core/context-types.d.ts
3
3
  /**
4
4
  * `unknown` when none of the `fields` is already a context field of the bus,
@@ -1,4 +1,4 @@
1
- import { I as PayloadOf, L as Task, P as EventMap } from "./action-creator-CbFf398i.js";
1
+ import { F as EventMap, L as PayloadOf, R as Task } from "./action-creator-D2CotugT.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 { P as EventMap, p as Bus } from "./action-creator-CbFf398i.js";
1
+ import { F as EventMap, p as Bus } from "./action-creator-D2CotugT.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 { R as EventMap, h as Bus, z as Keys } from "./action-creator-HFA_LZOH.js";
1
+ import { B as Keys, h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.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 ListenerOptions, R as EventMap, _ as Command, h as Bus, t as ActionCreator } from "./action-creator-HFA_LZOH.js";
1
+ import { V as ListenerOptions, _ as Command, h as Bus, t as ActionCreator, z as EventMap } from "./action-creator-Bpa8BUS9.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;
@@ -1,5 +1,5 @@
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";
1
+ import { B as Keys, N as WithContext, b as Context, d as Effects, h as Bus, l as BoundForm, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { n as NoClash } from "./context-types-BKIH5a8s.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 { 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";
1
+ import { W as Task, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { n as withPolicy, t as PolicyFunction } from "./with-policy-BeH8wCkX.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,7 @@
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";
1
+ import { T as EventKey, W as Task, h as Bus, r as FreeActionCreator, t as ActionCreator, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
2
  import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
3
- import { t as PolicyFunction } from "./with-policy-C_mX7S54.js";
3
+ import { t as PolicyFunction } from "./with-policy-BeH8wCkX.js";
4
+ import { t as StateOf } from "./state-of-C19H6BoV.js";
4
5
  //#region src/react/plugin.d.ts
5
6
  /** Tells whether two values are the same: `Object.is` unless the caller gives another. */
6
7
  type Equals<V> = (previous: V, next: V) => boolean;
@@ -46,8 +47,6 @@ type ReactApi<E extends EventMap> = {
46
47
  };
47
48
  /** What `useEventState` returns: the pair of `useState`, with the payload of the event as state. */
48
49
  type EventState<P> = [P, (next: P | ((previous: P) => P)) => void];
49
- type Widen<S> = [S] extends [never[]] ? unknown[] : S;
50
- type StateOf<P, S> = unknown extends P ? Widen<S> : P;
51
50
  /**
52
51
  * Adds `bus.useEmitter(event, value)`: a hook that tells the bus when a value of
53
52
  * a component changes, without the traps of `useEffect(() => emit(value), [value])`
package/dist/redux.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as EventMap, h as Bus } from "./action-creator-HFA_LZOH.js";
1
+ import { h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.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 { 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";
1
+ import { P as WithSignal, a as EmitScope, d as Effects, f as Signaled, h as Bus, o as Scope, u as Effect, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { n as ScopeSlots, r as Scoped } from "./types-CbdJKC2z.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
@@ -14,7 +14,7 @@ import { n as ScopeSlots, r as Scoped } from "./types-DaZT158m.js";
14
14
  *
15
15
  * @example
16
16
  * ```ts
17
- * const first = effect(<T>(ctx: { signal: AbortSignal }, items: T[]) => items[0]);
17
+ * const first = effect(<T>(ctx: WithSignal, items: T[]) => items[0]);
18
18
  *
19
19
  * const getUser = createCommand(
20
20
  * "user/get",
@@ -23,7 +23,7 @@ import { n as ScopeSlots, r as Scoped } from "./types-DaZT158m.js";
23
23
  * );
24
24
  * ```
25
25
  */
26
- export declare function effect<A extends unknown[], R>(fn: (ctx: Signaled, ...args: A) => R): (...args: A) => R;
26
+ export declare function effect<A extends unknown[], R>(fn: (ctx: WithSignal, ...args: A) => R): (...args: A) => R;
27
27
  //#endregion
28
28
  //#region src/scope/plugin.d.ts
29
29
  /**
package/dist/signal.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { C as Emit, E as EventLike, a as EmitScope, c as WithScope, h as Bus, v as CommandCall, z as EventMap } from "./action-creator-Bpa8BUS9.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 = {
@@ -0,0 +1,10 @@
1
+ //#region src/core/state-of.d.ts
2
+ type Widen<S> = [S] extends [never[]] ? unknown[] : S;
3
+ /**
4
+ * The type of the state that keeps the last payload of an event (`useEventState`,
5
+ * `useEventRef`): the payload type when the event has one, and otherwise the type of the
6
+ * initial value, widened, so a creator without a payload type still gives a typed state.
7
+ */
8
+ type StateOf<P, S> = unknown extends P ? Widen<S> : P;
9
+ //#endregion
10
+ export { StateOf as t };
package/dist/trace.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { G as Trace, K as TraceEvent, L as Tracer, R as EffectName, U as Phase, h as Bus, q as TraceLogger, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
2
  //#region src/trace/console.d.ts
3
3
  type ConsoleLoggerOptions = {
4
4
  /** Defaults to `globalThis.console`. */
@@ -1,5 +1,5 @@
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";
1
+ import { d as Effects, o as Scope, s as WithFields, z as EventMap } from "./action-creator-Bpa8BUS9.js";
2
+ import { t as BoundOf } from "./plugin-D9UTzGRG.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