nanoeffects 0.27.0 → 0.29.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 (84) hide show
  1. package/README.md +26 -24
  2. package/dist/{action-creator-D_c223C7.d.ts → action-creator-jeEqIKgK.d.ts} +73 -32
  3. package/dist/actions.d.ts +18 -18
  4. package/dist/actions.js +1 -1
  5. package/dist/bus-0uYn_kRj.js +1 -0
  6. package/dist/context-DtUnzC-1.js +1 -0
  7. package/dist/context-types-Bme1mzkn.d.ts +31 -0
  8. package/dist/context.d.ts +8 -3
  9. package/dist/context.js +1 -1
  10. package/dist/{delay-18LJ8jSk.js → delay-5OhJZZQ0.js} +1 -1
  11. package/dist/dev.d.ts +2 -2
  12. package/dist/dev.js +1 -1
  13. package/dist/effects.d.ts +2 -2
  14. package/dist/effects.js +1 -1
  15. package/dist/event-DVcW0mME.js +1 -0
  16. package/dist/index.d.ts +2 -2
  17. package/dist/index.js +1 -1
  18. package/dist/match.d.ts +3 -3
  19. package/dist/match.js +1 -1
  20. package/dist/{module-WX0Gngnt.d.ts → module-BWMW83qk.d.ts} +38 -38
  21. package/dist/notrace/{action-creator-Bux7Zzsl.d.ts → action-creator-xpQ_I2h8.d.ts} +73 -32
  22. package/dist/notrace/actions.d.ts +52 -52
  23. package/dist/notrace/actions.js +1 -1
  24. package/dist/notrace/bus-37nlVljc.js +1 -0
  25. package/dist/notrace/effects.d.ts +2 -2
  26. package/dist/notrace/index.d.ts +2 -2
  27. package/dist/notrace/index.js +1 -1
  28. package/dist/notrace/{plugin-CATXOxtj.d.ts → plugin-6LhNx0th.d.ts} +1 -1
  29. package/dist/notrace/policies.d.ts +1 -1
  30. package/dist/notrace/policies.js +1 -1
  31. package/dist/notrace/redux.d.ts +1 -1
  32. package/dist/observable.d.ts +43 -1
  33. package/dist/observable.js +1 -1
  34. package/dist/onAbort-BgMfspK4.js +1 -0
  35. package/dist/oop.d.ts +3 -3
  36. package/dist/oop.js +1 -1
  37. package/dist/{plugin-vvkmIIz2.d.ts → plugin-BaErevLy.d.ts} +2 -2
  38. package/dist/policies.d.ts +2 -2
  39. package/dist/policies.js +1 -1
  40. package/dist/react.d.ts +2 -2
  41. package/dist/react.js +1 -1
  42. package/dist/redux.d.ts +1 -1
  43. package/dist/scope.d.ts +9 -9
  44. package/dist/signal-field-key-CWT-3OXC.js +1 -0
  45. package/dist/signal.d.ts +34 -6
  46. package/dist/signal.js +1 -1
  47. package/dist/svelte.d.ts +1 -1
  48. package/dist/trace.d.ts +20 -5
  49. package/dist/trace.js +1 -1
  50. package/dist/{types-Bf-LX_tE.d.ts → types-D5xsR37j.d.ts} +2 -2
  51. package/dist/vue.d.ts +1 -1
  52. package/dist/{with-policy-CPjx0sLm.d.ts → with-policy-BZVRBUOm.d.ts} +1 -1
  53. package/dist/{with-policy-D-SQRkPh.js → with-policy-C6BIiPIi.js} +1 -1
  54. package/docs/README.md +14 -1
  55. package/docs/actions.md +28 -2
  56. package/docs/chat-example.md +16 -4
  57. package/docs/chat-widget.md +135 -0
  58. package/docs/context.md +33 -1
  59. package/docs/effects.md +20 -9
  60. package/docs/guide.md +21 -3
  61. package/docs/migrating-from-effector.md +11 -0
  62. package/docs/observable.md +43 -0
  63. package/docs/oop.md +18 -1
  64. package/docs/package.md +22 -13
  65. package/docs/plugins.md +69 -11
  66. package/docs/query-libraries.md +273 -5
  67. package/docs/react.md +12 -2
  68. package/docs/scope.md +14 -2
  69. package/docs/semantics.md +10 -0
  70. package/docs/server.md +3 -3
  71. package/docs/stability.md +2 -2
  72. package/docs/starter.md +3 -3
  73. package/docs/tracing.md +77 -9
  74. package/docs/typescript.md +1 -1
  75. package/llms-full.txt +816 -72
  76. package/llms.txt +8 -7
  77. package/package.json +6 -6
  78. package/skills/nanoeffects/SKILL.md +2 -2
  79. package/dist/bus-DQDHUN5e.js +0 -1
  80. package/dist/context-UcmrAIhP.js +0 -1
  81. package/dist/context-types-nGtzhjxD.d.ts +0 -14
  82. package/dist/event-0RIBGYqS.js +0 -1
  83. package/dist/notrace/bus-CGi2lrd5.js +0 -1
  84. package/dist/notrace/promise-CSLpzwSR.js +0 -1
package/dist/match.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { H as EventMap, Z as UnsubscribeCallback, h as Action, k as EventPayload, q as Task, v as Bus } from "./action-creator-D_c223C7.js";
1
+ import { D as EventPayload, H as EventMap, Z as UnsubscribeCallback, h as Action, q as Task, v as Bus } from "./action-creator-jeEqIKgK.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;
@@ -23,8 +23,8 @@ type MatchApi<E extends EventMap> = {
23
23
  * to subscribe to the events that it picks instead of to one named event. The
24
24
  * predicate gets `{ type, payload }` of every event; when it returns true the
25
25
  * handler runs with the payload and the task context of that event. A type guard
26
- * narrows the payload of the handler. An action creator or a command, which have
27
- * a string `type`, keep their meaning. Returns the same bus.
26
+ * narrows the payload of the handler. An action creator, which has
27
+ * a string `type`, keeps its meaning. Returns the same bus.
28
28
  *
29
29
  * The subscription listens to `"*"`, so it runs after the listeners of the event
30
30
  * itself, makes a task for every event whether or not the predicate accepts it,
package/dist/match.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e==`function`&&typeof Reflect.get(e,`type`)!=`string`,t=e=>e,n=()=>n=>{let{on:r,once:i,off:a}=n,o=/* @__PURE__ */ new Map,s=(e,t,i)=>{let a=Reflect.apply(r,n,[`*`,(n,r)=>{if(e({type:Reflect.get(r,`type`),payload:n}))return i&&c(),t(n,r)}]),s={handler:t,remove:c};o.set(e,[...o.get(e)??[],s]);function c(){a();let t=(o.get(e)??[]).filter(e=>e!==s);t.length>0?o.set(e,t):o.delete(e)}return c},c=(t,a,o,c)=>e(t)?s(t,a,o):Reflect.apply(o?i:r,n,[t,a,c]);return Object.assign(n,t({on:(e,t,n)=>c(e,t,!1,n),once:(e,t,n)=>c(e,t,!0,n),off:(t,r)=>{if(r===void 0&&(t===void 0||t===`*`)&&o.clear(),!e(t))return Reflect.apply(a,n,[t,r]);let i=o.get(t)??[],s=i.filter(e=>e.handler===r),c=r===void 0?i:s.slice(0,1);for(let e of c)e.remove()}}))};export{n as matchPlugin};
1
+ const e=e=>typeof e==`function`&&typeof Reflect.get(e,`type`)!=`string`,t=e=>e,n=()=>n=>{let{on:r,once:i,off:a}=n,o=/* @__PURE__ */ new Map,s=(e,t,i,a)=>{let s=Reflect.apply(r,n,[`*`,(n,r)=>{if(e({type:Reflect.get(r,`type`),payload:n}))return i&&l(),t(n,r)},a]),c={handler:t,remove:l};o.set(e,[...o.get(e)??[],c]);function l(){s();let t=(o.get(e)??[]).filter(e=>e!==c);t.length>0?o.set(e,t):o.delete(e)}return l},c=(t,a,o,c)=>e(t)?s(t,a,o,c):Reflect.apply(o?i:r,n,[t,a,c]);return Object.assign(n,t({on:(e,t,n)=>c(e,t,!1,n),once:(e,t,n)=>c(e,t,!0,n),off:(t,r)=>{if(r===void 0&&(t===void 0||t===`*`)&&o.clear(),!e(t))return Reflect.apply(a,n,[t,r]);let i=o.get(t)??[],s=i.filter(e=>e.handler===r),c=r===void 0?i:s.slice(0,1);for(let e of c)e.remove()}}))};export{n as matchPlugin};
@@ -1,10 +1,10 @@
1
- import { G as PayloadOf, H as EventMap, R as commandCall, S as Context, Z as UnsubscribeCallback, b as Command, c as Scope, g as Actions, q as Task, u as WithScope, v as Bus, x as CommandCall } from "./action-creator-D_c223C7.js";
2
- import { n as ScopeSlots, r as Scoped } from "./types-Bf-LX_tE.js";
3
- //#region src/actions/command.d.ts
4
- /** What `createCommand` returns: a command that also tells whether an action is of its type. */
5
- type MadeCommand<P, R, T extends string> = Command<P, R> & {
1
+ import { A as HandledCall, G as PayloadOf, H as EventMap, Z as UnsubscribeCallback, b as Context, c as Scope, g as Actions, k as Handled, q as Task, u as WithScope, v as Bus, z as handledCall } from "./action-creator-jeEqIKgK.js";
2
+ import { n as ScopeSlots, r as Scoped } from "./types-D5xsR37j.js";
3
+ //#region src/actions/handled.d.ts
4
+ /** What `createAction` returns: an action that also tells whether an action is of its type. */
5
+ type MadeHandled<P, R, T extends string> = Handled<P, R> & {
6
6
  readonly type: T;
7
- /** Tells whether an action has the type of this command, and narrows its type. */
7
+ /** Tells whether an action has the type of this action, and narrows its type. */
8
8
  match(action: {
9
9
  type: string;
10
10
  payload?: unknown;
@@ -14,14 +14,14 @@ type MadeCommand<P, R, T extends string> = Command<P, R> & {
14
14
  };
15
15
  };
16
16
  /** `Made`, called so that its calls carry the scope fields `F`; `Made` itself when there are none. */
17
- type CarryingCalls<Made, P, R, F> = [unknown] extends [F] ? Made : ((payload: P) => CommandCall<P, R> & WithScope<F>) & Made & WithScope<F>;
18
- /** A command made with a scope: its calls carry the fields of that scope, for the checker. */
19
- type ScopedCommand<P, R, T extends string, F> = ((payload: P) => CommandCall<P, R> & WithScope<F>) & MadeCommand<P, R, T> & WithScope<F>;
20
- /** A command (or its type) with the handler to bind to it; `setHandler` makes one. */
21
- type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
17
+ type CarryingCalls<Made, P, R, F> = [unknown] extends [F] ? Made : ((payload: P) => HandledCall<P, R> & WithScope<F>) & Made & WithScope<F>;
18
+ /** An action made with a scope: its calls carry the fields of that scope, for the checker. */
19
+ type ScopedHandled<P, R, T extends string, F> = ((payload: P) => HandledCall<P, R> & WithScope<F>) & MadeHandled<P, R, T> & WithScope<F>;
20
+ /** An action (or its type) with the handler to bind to it; `setHandler` makes one. */
21
+ type Binding<E extends EventMap = EventMap> = readonly [Handled<never, unknown> | string, Task<never, E, unknown>];
22
22
  /**
23
23
  * Pairs an action with the handler to bind to it, for `actionsPlugin`. For a
24
- * command (an action made with a handler, or with a `Call` type) it checks that
24
+ * action (an action made with a handler, or with a `Call` type) it checks that
25
25
  * the handler fits; any other action is accepted with a handler of any payload.
26
26
  *
27
27
  * @example
@@ -29,21 +29,21 @@ type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown>
29
29
  * bus.use(actionsPlugin([setHandler(sendMail, smtpSend)]));
30
30
  * ```
31
31
  */
32
- declare function setHandler<P, R, E extends EventMap>(command: Command<P, R>, fn: Task<P, E, R>): Binding<E>;
32
+ declare function setHandler<P, R, E extends EventMap>(handled: Handled<P, R>, fn: Task<P, E, R>): Binding<E>;
33
33
  declare function setHandler<A extends {
34
34
  readonly type: string;
35
35
  }, E extends EventMap>(action: A, fn: LooseHandler<A, E>): Binding<E>;
36
36
  /**
37
- * The handler an action that is not a command can have: any. A command
38
- * (a creator whose calls are command calls) is not accepted here, so its own
37
+ * The handler an action that is not an action can have: any. An action
38
+ * (a creator whose calls are calls of an action with a handler) is not accepted here, so its own
39
39
  * overload checks the handler against its payload and result.
40
40
  */
41
41
  type LooseHandler<A, E extends EventMap> = A extends ((...args: never[]) => {
42
- readonly [commandCall]: unknown;
42
+ readonly [handledCall]: unknown;
43
43
  }) ? never : Task<never, E, unknown>;
44
44
  /** The registry of handlers that `actionsPlugin` returns: `run` for the bus, `handle` to bind more. */
45
45
  interface Registry$1<E extends EventMap> extends Actions {
46
- handle<P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
46
+ handle<P, R>(handled: Handled<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
47
47
  /** Also an action made without a handler: what is emitted for its type runs `fn` and returns its result. */
48
48
  handle<A extends {
49
49
  readonly type: string;
@@ -52,25 +52,25 @@ interface Registry$1<E extends EventMap> extends Actions {
52
52
  handle(bindings: readonly Binding<E>[]): UnsubscribeCallback;
53
53
  }
54
54
  /**
55
- * The plugin that gives a bus the handlers bound to commands:
55
+ * The plugin that gives a bus the handlers bound to actions:
56
56
  * `bus.use(actionsPlugin(bindings))` makes the registry, sets it as the
57
- * commands of the bus and returns it. Each bus has its own, so each test can
57
+ * actions of the bus and returns it. Each bus has its own, so each test can
58
58
  * have its own implementation. `handle` binds more later and returns the
59
59
  * function that unbinds. A second `actionsPlugin` on the same bus binds its
60
60
  * list in the registry that is there and returns it, so the order of the
61
- * plugins does not matter. A `commands` that is not such a registry (a custom
61
+ * plugins does not matter. A `actions` that is not such a registry (a custom
62
62
  * runner) is replaced.
63
63
  *
64
- * What the bus runs for a command: the handler bound last, else the one the
65
- * command was created with, else it throws `No handler for command "..."`.
64
+ * What the bus runs for an action: the handler bound last, else the one the
65
+ * action was created with, else it throws `No handler for action "..."`.
66
66
  *
67
67
  * @example
68
68
  * ```ts
69
69
  * const bus = createBus<Events>();
70
- * const commands = bus.use(actionsPlugin([setHandler(sendMail, smtpSend)]));
70
+ * const actions = bus.use(actionsPlugin([setHandler(sendMail, smtpSend)]));
71
71
  *
72
- * const unbind = commands.handle(getUser, async () => fakeUser);
73
- * unbind(); // the command's own handler is back
72
+ * const unbind = actions.handle(getUser, async () => fakeUser);
73
+ * unbind(); // the action's own handler is back
74
74
  * ```
75
75
  */
76
76
  declare const actionsPlugin: <E extends EventMap>(bindings?: readonly Binding<E>[]) => (bus: Bus<E>) => Registry$1<E>;
@@ -78,23 +78,23 @@ declare const actionsPlugin: <E extends EventMap>(bindings?: readonly Binding<E>
78
78
  //#region src/actions/module.d.ts
79
79
  /**
80
80
  * What a module's `setup` gets: the context of the module's task, so `on`,
81
- * `emit` and `run` work as in a handler, plus `handle` to bind commands, `use`
81
+ * `emit` and `run` work as in a handler, plus `handle` to bind actions, `use`
82
82
  * to mount sub-modules and `spawn` to start a background task. Everything the
83
83
  * module does is undone when it is unmounted.
84
84
  */
85
85
  type ModuleContext<E extends EventMap = EventMap> = Context<E> & {
86
- /** Binds the handler of a command, or a list of them; undone on unmount. */
87
- handle<P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
88
- /** Also an action made without a handler: the handler answers it as it would a command. */
86
+ /** Binds the handler of an action, or a list of them; undone on unmount. */
87
+ handle<P, R>(handled: Handled<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
88
+ /** Also an action made without a handler: the handler answers it as it would one made with a handler. */
89
89
  handle<A extends {
90
90
  readonly type: string;
91
91
  }>(action: A, fn: LooseHandler<A, E>): UnsubscribeCallback;
92
92
  handle(type: string, fn: Task<never, E, unknown>): UnsubscribeCallback;
93
93
  handle(bindings: readonly Binding<E>[]): UnsubscribeCallback;
94
94
  /**
95
- * Brings sub-modules and commands, in any order. A sub-module is mounted and
96
- * unmounted with this one. A command is bound to the handler it carries, for
97
- * as long as this module is mounted; a command that answers by itself keeps
95
+ * Brings sub-modules and actions, in any order. A sub-module is mounted and
96
+ * unmounted with this one. An action is bound to the handler it carries, for
97
+ * as long as this module is mounted; an action that answers by itself keeps
98
98
  * answering after the module is gone, since the handler is its own. The
99
99
  * returned function undoes just this call, e.g. for what was added later from
100
100
  * a listener.
@@ -116,7 +116,7 @@ type Module<E extends EventMap = EventMap> = {
116
116
  readonly scope?: Scope;
117
117
  };
118
118
  /**
119
- * Describes one domain of an app: the commands it handles, the events it
119
+ * Describes one domain of an app: the actions it handles, the events it
120
120
  * listens to, its sub-modules and its background tasks. The `name` shows up as
121
121
  * the type of the module's tasks in the trace.
122
122
  *
@@ -158,7 +158,7 @@ interface WithApp {
158
158
  }
159
159
  /** What `modulePlugin` returns. */
160
160
  type ModuleApi<E extends EventMap = EventMap> = {
161
- /** The registry of command handlers of the bus: the one it was made with, or the app's own. */
161
+ /** The registry of action handlers of the bus: the one it was made with, or the app's own. */
162
162
  actions: Registry<E>;
163
163
  /**
164
164
  * Mounts modules, in the order given, and returns the function that unmounts them, last
@@ -187,17 +187,17 @@ type ModuleApi<E extends EventMap = EventMap> = {
187
187
  * of one of its methods. By then every plugin is on the bus, so the plugins can
188
188
  * be used in any order. The `on`, `once` and `off` calls made in between are
189
189
  * held and made right after the modules, so the listeners of a module stay
190
- * ahead of them. The bus runs the commands that the modules bind: the registry
190
+ * ahead of them. The bus runs the actions that the modules bind: the registry
191
191
  * that the bus has is used (a later `actionsPlugin` binds in it), otherwise the
192
192
  * app attaches its own, as `app.actions`. The app is also `bus.app`.
193
193
  *
194
194
  * A module is known by its `name`: mounting a module whose name is taken
195
195
  * replaces the mounted one, which is unmounted first. That is what hot reload
196
196
  * needs (see `docs/hmr.md`): the new version of a module file mounts again and
197
- * the old version goes away with its subscriptions, commands and tasks.
197
+ * the old version goes away with its subscriptions, actions and tasks.
198
198
  *
199
199
  * Unmounting undoes everything the module did: its subscriptions, its bound
200
- * commands, its sub-modules and its background tasks. `dispose` unmounts them
200
+ * actions, its sub-modules and its background tasks. `dispose` unmounts them
201
201
  * all, and a disposed app cannot mount modules.
202
202
  *
203
203
  * @example
@@ -220,4 +220,4 @@ type ModuleApi<E extends EventMap = EventMap> = {
220
220
  */
221
221
  declare const modulePlugin: <E extends EventMap>(modules?: readonly Module<E>[]) => (bus: Bus<E> & ScopeSlots & WithApp) => ModuleApi<E>;
222
222
  //#endregion
223
- export { createModule as a, CarryingCalls as c, actionsPlugin as d, setHandler as f, WithApp as i, MadeCommand as l, ModuleApi as n, modulePlugin as o, ModuleContext as r, Binding as s, Module as t, ScopedCommand as u };
223
+ export { createModule as a, CarryingCalls as c, actionsPlugin as d, setHandler as f, WithApp as i, MadeHandled as l, ModuleApi as n, modulePlugin as o, ModuleContext as r, Binding as s, Module as t, ScopedHandled as u };
@@ -1,19 +1,42 @@
1
1
  //#region src/core/types.d.ts
2
- /** The third argument of `on` and `once`: read by `tracePlugin`, ignored without it. */
2
+ /** The third argument of `on` and `once`: each field is read by the plugin that names it, ignored without it. */
3
3
  type ListenerOptions = {
4
- /** Names the listener in the trace: each call of it is a task with this `type`. */
4
+ /** Names the listener in the trace: each call of it is a task with this `type`. Read by `tracePlugin`. */
5
5
  traceId?: string;
6
+ /** Removes the listener when this aborts, and adds none if it aborted already. Read by `signalPlugin`. */
7
+ signal?: AbortSignal;
6
8
  };
7
9
  type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
8
10
  type EventMap = Record<string, unknown>;
9
11
  type Keys<E> = keyof E & string;
10
12
  type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
11
- type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command" | "emit";
13
+ type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "action" | "emit";
12
14
  type Phase = "start" | "done" | "error" | "cancel" | "drop";
13
15
  type UnsubscribeCallback = () => void;
14
16
  //#endregion
15
17
  //#region src/core/store.d.ts
16
18
  declare const anyEventType = "*";
19
+ type AnyType = "*";
20
+ interface UnsubscribeTask<E extends EventMap> {
21
+ (task: Task<DataOf<E[Keys<E>]>, E>): void;
22
+ <K extends AnyType>(key: K, task?: Task<DataOf<E[Keys<E>]>, E>): void;
23
+ <K extends Keys<E>>(key: K, task?: Task<DataOf<E[K]>, E>): void;
24
+ }
25
+ type Store<E extends EventMap> = {
26
+ get: {
27
+ /** Every listener of every event, in the order of the events. */
28
+ (): Task<DataOf<E[Keys<E>]>, E>[];
29
+ (key: AnyType): Task<DataOf<E[Keys<E>]>, E>[];
30
+ <K extends Keys<E>>(key: K): Task<DataOf<E[K]>, E>[];
31
+ };
32
+ add: {
33
+ (key: AnyType, task: Task<DataOf<E[Keys<E>]>, E>): UnsubscribeCallback;
34
+ <K extends Keys<E>>(key: K, task: Task<DataOf<E[K]>, E>): UnsubscribeCallback;
35
+ };
36
+ remove: UnsubscribeTask<E>;
37
+ /** Drops every key; lists already handed out by `get` stay as they were. */
38
+ clear: () => void;
39
+ };
17
40
  //#endregion
18
41
  //#region src/core/tracer.d.ts
19
42
  /**
@@ -77,27 +100,27 @@ type Action<E extends EventMap> = {
77
100
  };
78
101
  type EventLike<E extends EventMap> = { [K in EventKey<E>]: WithPayload<E, K>; }[Keys<E>];
79
102
  /**
80
- * Brands `{ type, payload }` from a command call so `emit` can run the command.
103
+ * Brands `{ type, payload }` from a call of an action with a handler so `emit` can run the action.
81
104
  * Not enumerable on the object.
82
105
  */
83
- declare const commandCall: unique symbol;
106
+ declare const handledCall: unique symbol;
84
107
  /**
85
- * What `command(payload)` returns: an action-shaped value that `emit` runs as
86
- * that command. A plain `{ type, payload }` without this brand is notify-only.
108
+ * What `action(payload)` returns: an action-shaped value that `emit` runs as
109
+ * that action. A plain `{ type, payload }` without this brand is notify-only.
87
110
  */
88
- type CommandCall<P = unknown, R = unknown> = {
111
+ type HandledCall<P = unknown, R = unknown> = {
89
112
  type: string;
90
113
  payload: P;
91
- readonly [commandCall]: Command<P, R>;
114
+ readonly [handledCall]: Handled<P, R>;
92
115
  };
93
116
  /**
94
117
  * A typed request for a result. Calling it builds `{ type, payload }` like
95
- * `createAction`; `bus.emit(command(payload))` (or `bus.emit(command, payload)`)
118
+ * `createAction`; `bus.emit(action(payload))` (or `bus.emit(action, payload)`)
96
119
  * runs the handler as a task and returns what it returns. Made by
97
- * `createCommand` in `nanoeffects/actions`.
120
+ * `createAction` in `nanoeffects/actions`.
98
121
  */
99
- type Command<P = never, R = unknown> = {
100
- (payload: P): CommandCall<P, R>;
122
+ type Handled<P = never, R = unknown> = {
123
+ (payload: P): HandledCall<P, R>;
101
124
  readonly type: string;
102
125
  /** Wraps the handler that really runs, e.g. to route its outcome. */
103
126
  readonly wrap?: (run: (payload: never, ctx: never) => unknown) => (payload: never, ctx: never) => unknown;
@@ -107,15 +130,15 @@ type Command<P = never, R = unknown> = {
107
130
  * `actionsPlugin` in `nanoeffects/actions`, holds the handlers bound to
108
131
  * actions and runs the right one, so a bus without `actions` carries none of
109
132
  * that. `bound` tells, for an event type, whether a handler is bound to it: an
110
- * action with no handler of its own is a command only then. A runner that has
111
- * no `bound` runs commands only.
133
+ * action with no handler of its own is an action only then. A runner that has
134
+ * no `bound` runs actions only.
112
135
  */
113
136
  interface Actions {
114
- run(command: Command, payload: unknown, ctx: unknown): unknown;
115
- bound?(type: string): Command | undefined;
137
+ run(handled: Handled, payload: unknown, ctx: unknown): unknown;
138
+ bound?(type: string): Handled | undefined;
116
139
  }
117
- /** Anything `emit` takes as its first argument: an event type, an action or a command. */
118
- type Emittable<E extends EventMap> = EventKey<E> | Command | CommandCall | EventLike<E>;
140
+ /** Anything `emit` takes as its first argument: an event type, an action creator or a call of one. */
141
+ type Emittable<E extends EventMap> = EventKey<E> | Handled | HandledCall | EventLike<E>;
119
142
  type Emit<E extends EventMap> = {
120
143
  /**
121
144
  * On a bus without an event map the caller can say what a handler bound for
@@ -124,11 +147,11 @@ type Emit<E extends EventMap> = {
124
147
  */
125
148
  <R = void>(type: string extends EventKey<E> ? string : never, ...payload: unknown[]): R;
126
149
  <K extends EventKey<E>>(event: K, ...payload: PayloadOf<DataOf<E[K]>>): ResultOf<E[K]>;
127
- /** Before Handler: a command is callable too, and must return its result type. */
128
- <P, R>(command: Command<P, R>, ...payload: PayloadOf<P>): R;
150
+ /** Before Handler: an action is callable too, and must return its result type. */
151
+ <P, R>(handled: Handled<P, R>, ...payload: PayloadOf<P>): R;
129
152
  /** A scope as the second argument replaces context fields for the tasks of this emit; see `scopePlugin`. */
130
- <P, R, F>(call: CommandCall<P, R> & WithScope<F>, scope?: EmitScope<E, F>): R;
131
- <P, R>(call: CommandCall<P, R>, scope?: EmitScope<E>): R;
153
+ <P, R, F>(call: HandledCall<P, R> & WithScope<F>, scope?: EmitScope<E, F>): R;
154
+ <P, R>(call: HandledCall<P, R>, scope?: EmitScope<E>): R;
132
155
  <K extends EventKey<E>, R>(event: Handler<E, R, K>, ...payload: PayloadOf<DataOf<E[K]>>): R;
133
156
  <F>(event: EventLike<E> & WithScope<F>, scope?: EmitScope<E, F>): void;
134
157
  (event: EventLike<E>, scope?: EmitScope<E>): void;
@@ -137,15 +160,15 @@ type On<E extends EventMap> = {
137
160
  (event: AnyEvent, fn: Task<EventPayload<E>, E>, options?: ListenerOptions): UnsubscribeCallback;
138
161
  <K extends EventKey<E>>(event: K, fn: Task<DataOf<E[K]>, E>, options?: ListenerOptions): UnsubscribeCallback;
139
162
  /** An action creator without a payload type: the payload comes from the event map. */
140
- /** The creators and commands that carry a scope come first: the handler sees their fields. */
163
+ /** The creators and actions that carry a scope come first: the handler sees their fields. */
141
164
  <K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<DataOf<E[K]>, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
142
165
  <P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
143
- <P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
166
+ <P, F>(handled: Handled<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
144
167
  <K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<DataOf<E[K]>, E>, options?: ListenerOptions): UnsubscribeCallback;
145
168
  /** An action creator: the payload comes from it, so an event map is not needed. */
146
169
  <P>(creator: ActionCreator<P>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
147
- /** A command: the payload comes from it too. */
148
- <P>(command: Command<P, unknown>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
170
+ /** An action: the payload comes from it too. */
171
+ <P>(handled: Handled<P, unknown>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
149
172
  <K extends EventKey<E>, Event extends {
150
173
  type: K;
151
174
  }>(event: Event & {
@@ -164,7 +187,7 @@ type Off<E extends EventMap> = {
164
187
  }>(event: Event & {
165
188
  type: K;
166
189
  }, fn: Task<DataOf<E[K]>, E>): void;
167
- <P>(command: Command<P, unknown>, fn?: Task<P, E>): void;
190
+ <P>(handled: Handled<P, unknown>, fn?: Task<P, E>): void;
168
191
  };
169
192
  declare const contextKey: unique symbol;
170
193
  /**
@@ -227,6 +250,24 @@ interface Bus<E extends EventMap> {
227
250
  */
228
251
  once: On<E>;
229
252
  off: Off<E>;
253
+ /**
254
+ * The listeners an event has right now, in the order they run: what `on`,
255
+ * `once`, `ctx.on` and the `on` of a module registered, as the bus holds them
256
+ * (a plugin may have wrapped a function, so compare the length, not the
257
+ * functions). It takes the event name as a string, as the bus stores it, not
258
+ * an action creator: use `creator.type`. `"*"` gives the any-event listeners,
259
+ * which a named event does not include. The array is not changed afterwards: a later `on` or unbind
260
+ * gives the next `get` a new one.
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * const unbind = bus.on("saved", save);
265
+ * bus.get("saved").length; // 1
266
+ * unbind();
267
+ * bus.get("saved").length; // 0
268
+ * ```
269
+ */
270
+ get: Store<E>["get"];
230
271
  emit: Emit<E>;
231
272
  /**
232
273
  * Calls `plugin` with the bus and returns what it returns: an api, a
@@ -236,7 +277,7 @@ interface Bus<E extends EventMap> {
236
277
  use<R>(plugin: (bus: Bus<E>) => R): R;
237
278
  /** `BusOptions.context` and `.trace`, and `actions`, for what makes tasks of its own, like `modulePlugin`. */
238
279
  readonly ctx?: ContextOption<E> | undefined;
239
- /** What runs the handlers of actions; `actionsPlugin` and `modulePlugin` set it. Without one a command runs its own handler. */
280
+ /** What runs the handlers of actions; `actionsPlugin` and `modulePlugin` set it. Without one an action runs its own handler. */
240
281
  actions?: Actions | undefined;
241
282
  readonly trace?: Tracer | undefined;
242
283
  /** Called with every new task context to add fields to it, for what needs the task, like `effectsPlugin`. Chain to the previous one. */
@@ -255,7 +296,7 @@ type BusOptions<E extends EventMap> = {
255
296
  onError?: (error: unknown, event: Action<E>) => void;
256
297
  /**
257
298
  * Called when an event is emitted and nobody listens to it: the usual sign
258
- * of a typo in an event name. Not called for commands, nor for an action with
299
+ * of a typo in an event name. Not called for actions, nor for an action with
259
300
  * a handler bound in `actions`, which always have a handler to run. Typically a warning in development only.
260
301
  *
261
302
  * @example
@@ -306,7 +347,7 @@ type BoundForm<F> = typeof bound extends keyof F ? NonNullable<F[typeof bound &
306
347
  //#endregion
307
348
  //#region src/core/scope-types.d.ts
308
349
  declare const scopeFields: unique symbol;
309
- /** What an action creator, a command or a call knows of the scope it was made with: its fields, for the checker. */
350
+ /** What an action creator or a call knows of the scope it was made with: its fields, for the checker. */
310
351
  type WithScope<F> = {
311
352
  readonly [scopeFields]: F;
312
353
  };
@@ -415,4 +456,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
415
456
  toString(): T;
416
457
  }
417
458
  //#endregion
418
- export { Off as A, Task as B, Emittable as C, EventsOf as D, EventPayload as E, commandCall as F, createBus as I, EventMap as L, WithContext as M, WithSignal as N, Handler as O, WithType as P, Keys as R, Emit as S, EventLike as T, UnsubscribeCallback as V, Command as _, WithPayload as a, ContextOf as b, WithScope as c, Effects as d, Action as f, BusOptions as g, Bus as h, FreeActionCreator as i, On as j, HandlerRef as k, BoundForm as l, AnyEvent as m, Call as n, Scope as o, Actions as p, Free as r, WithFields as s, ActionCreator as t, Effect as u, CommandCall as v, EventKey as w, ContextOption as x, Context as y, PayloadOf as z };
459
+ export { Off as A, Task as B, EventLike as C, HandledCall as D, Handled as E, createBus as F, handledCall as I, EventMap as L, WithContext as M, WithSignal as N, Handler as O, WithType as P, Keys as R, EventKey as S, EventsOf as T, UnsubscribeCallback as V, Context as _, WithPayload as a, Emit as b, WithScope as c, Effects as d, Action as f, BusOptions as g, Bus as h, FreeActionCreator as i, On as j, HandlerRef as k, BoundForm as l, AnyEvent as m, Call as n, Scope as o, Actions as p, Free as r, WithFields as s, ActionCreator as t, Effect as u, ContextOf as v, EventPayload as w, Emittable as x, ContextOption as y, PayloadOf as z };