nanoeffects 0.2.1 → 0.4.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 (42) hide show
  1. package/README.md +50 -55
  2. package/dist/{action-rqZEnRIp.d.ts → action-creator-D48fp13T.d.ts} +66 -74
  3. package/dist/actions.d.ts +54 -20
  4. package/dist/actions.js +1 -1
  5. package/dist/bus-Cho463Sq.js +1 -0
  6. package/dist/dev.d.ts +2 -2
  7. package/dist/effects.d.ts +1 -1
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +1 -1
  10. package/dist/{module-BSCdR9D1.d.ts → module-DVX8aYlq.d.ts} +39 -25
  11. package/dist/notrace/{action-rqZEnRIp.d.ts → action-creator-D48fp13T.d.ts} +66 -74
  12. package/dist/notrace/actions.d.ts +90 -42
  13. package/dist/notrace/actions.js +1 -1
  14. package/dist/notrace/bus-B12SvxLv.js +1 -0
  15. package/dist/notrace/effects.d.ts +1 -1
  16. package/dist/notrace/index.d.ts +2 -2
  17. package/dist/notrace/index.js +1 -1
  18. package/dist/notrace/policies.d.ts +1 -1
  19. package/dist/notrace/redux.d.ts +1 -1
  20. package/dist/notrace/redux.js +1 -1
  21. package/dist/observable.d.ts +1 -1
  22. package/dist/policies.d.ts +1 -1
  23. package/dist/redux.d.ts +1 -1
  24. package/dist/redux.js +1 -1
  25. package/dist/trace.d.ts +1 -1
  26. package/docs/README.md +24 -9
  27. package/docs/actions.md +118 -42
  28. package/docs/context.md +27 -8
  29. package/docs/effects.md +152 -73
  30. package/docs/errors.md +23 -10
  31. package/docs/guide.md +236 -129
  32. package/docs/hmr.md +25 -13
  33. package/docs/observable.md +10 -9
  34. package/docs/package.md +14 -0
  35. package/docs/policies.md +92 -30
  36. package/docs/semantics.md +5 -3
  37. package/docs/stores.md +96 -22
  38. package/docs/tracing.md +69 -54
  39. package/package.json +5 -4
  40. package/dist/bus-CRnlwmQ4.js +0 -1
  41. package/dist/notrace/bus-Dx0l9X6h.js +0 -1
  42. package/dist/notrace/event-0RIBGYqS.js +0 -1
@@ -1,17 +1,32 @@
1
- import { L as UnsubscribeCallback, N as Task, c as Command, j as PayloadOf, k as EventMap, o as Bus, u as Context } from "./action-rqZEnRIp.js";
1
+ import { S as Context, _ as Bus, c as PayloadOf, m as UnsubscribeCallback, o as EventMap, u as Task, y as Command } from "./action-creator-D48fp13T.js";
2
2
  //#region src/actions/command.d.ts
3
+ /** What `createCommand` returns: a command that also tells whether an action is of its type. */
4
+ type MadeCommand<P, R, T extends string> = Command<P, R> & {
5
+ readonly type: T;
6
+ /** Tells whether an action has the type of this command, and narrows its type. */
7
+ match(action: {
8
+ type: string;
9
+ payload?: unknown;
10
+ }): action is {
11
+ type: T;
12
+ payload: P;
13
+ };
14
+ };
3
15
  /**
4
- * Creates a command: a typed request for a result. `bus.emit(command, payload)`
5
- * runs its handler as a task, with a context, and returns what the handler
6
- * returns. Listeners of the command's type are told first, as for any event.
16
+ * Creates a command: a typed request for a result. Calling it builds
17
+ * `{ type, payload }` like `createAction`. `bus.emit(command(payload))` (or
18
+ * `bus.emit(command, payload)`) runs its handler as a task, with a context, and
19
+ * returns what the handler returns. Listeners of the command's type are told
20
+ * first, as for any event.
7
21
  *
8
22
  * The handler is optional. A command without one is only a contract, and the
9
23
  * bus gets its implementation from the `commands` registry (see
10
- * `createCommands` and `bindHandler`). A handler bound there wins over the one
24
+ * `commandsPlugin` and `bindHandler`). A handler bound there wins over the one
11
25
  * the command was created with, so a test can give a bus its own implementation.
12
26
  *
13
- * A handler can be wrapped in a policy, e.g. `latest(fn)`. Calling the command
14
- * directly, `command(payload)`, runs its own handler outside of any bus.
27
+ * A handler can be wrapped in a policy, e.g. `latest(fn)`.
28
+ * `command.match(action)` tells whether an action has the type of the command,
29
+ * as it does for an action creator.
15
30
  *
16
31
  * @example
17
32
  * ```ts
@@ -20,34 +35,33 @@ import { L as UnsubscribeCallback, N as Task, c as Command, j as PayloadOf, k as
20
35
  * );
21
36
  * const sendMail = createCommand<Mail, void>("mail/send"); // implemented elsewhere
22
37
  *
23
- * const commands = createCommands([bindHandler(sendMail, smtpSend)]);
24
- * const bus = createBus({ commands });
25
- * const user = await bus.emit(getUser, "1");
38
+ * const bus = createBus<Events>();
39
+ * bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
40
+ * const user = await bus.emit(getUser("1"));
26
41
  *
27
42
  * commands.handle(getUser, async () => fakeUser); // in a test
28
43
  * ```
29
44
  */
30
- declare const createCommand: <P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>) => Command<P, R> & {
31
- readonly type: T;
32
- };
45
+ declare const createCommand: <P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>) => MadeCommand<P, R, T>;
33
46
  /** A command (or its type) with the handler to bind to it; `bindHandler` makes one. */
34
47
  type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
35
48
  /**
36
- * Pairs a command with the handler to bind to it, for `createCommands`. It
49
+ * Pairs a command with the handler to bind to it, for `commandsPlugin`. It
37
50
  * checks that the handler fits the command.
38
51
  *
39
52
  * @example
40
53
  * ```ts
41
- * createCommands([bindHandler(sendMail, smtpSend)]);
54
+ * bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
42
55
  * ```
43
56
  */
44
57
  declare const bindHandler: <P, R, E extends EventMap>(command: Command<P, R>, fn: Task<P, E, R>) => Binding<E>;
45
58
  /**
46
- * The handlers bound to commands of `bus`: it makes the registry, sets it as
47
- * the commands of the bus and returns it. Each bus has its own, so each test
48
- * can have its own implementation. `handle` binds more later and returns the
49
- * function that unbinds. A second `createCommands(bus)` replaces the registry
50
- * of that bus.
59
+ * The plugin that gives a bus the handlers bound to commands:
60
+ * `bus.use(commandsPlugin(bindings))` makes the registry, sets it as the
61
+ * commands of the bus and returns it. Each bus has its own, so each test can
62
+ * have its own implementation. `handle` binds more later and returns the
63
+ * function that unbinds. A second `commandsPlugin` on the same bus replaces
64
+ * the registry of that bus.
51
65
  *
52
66
  * What the bus runs for a command: the handler bound last, else the one the
53
67
  * command was created with, else it throws `No handler for command "..."`.
@@ -55,13 +69,13 @@ declare const bindHandler: <P, R, E extends EventMap>(command: Command<P, R>, fn
55
69
  * @example
56
70
  * ```ts
57
71
  * const bus = createBus<Events>();
58
- * const commands = createCommands(bus, [bindHandler(sendMail, smtpSend)]);
72
+ * const commands = bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
59
73
  *
60
74
  * const unbind = commands.handle(getUser, async () => fakeUser);
61
75
  * unbind(); // the command's own handler is back
62
76
  * ```
63
77
  */
64
- declare const createCommands: <E extends EventMap>(bus: Bus<E>, bindings?: readonly Binding<E>[]) => {
78
+ declare const commandsPlugin: <E extends EventMap>(bindings?: readonly Binding<E>[]) => (bus: Bus<E>) => {
65
79
  run: (command: Command, payload: unknown, ctx: unknown) => unknown;
66
80
  handle: {
67
81
  <P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
@@ -121,7 +135,7 @@ type Module<E extends EventMap = EventMap> = {
121
135
  * ```
122
136
  */
123
137
  declare const createModule: <E extends EventMap = EventMap>(name: string, setup: (m: ModuleContext<E>) => void) => Module<E>;
124
- type Registry<E extends EventMap> = ReturnType<typeof createCommands<E>>;
138
+ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<E>>>;
125
139
  /** What `modulePlugin` returns. */
126
140
  type ModuleApi<E extends EventMap = EventMap> = {
127
141
  /** The registry of command handlers of the bus: the one it was made with, or the app's own. */
@@ -137,7 +151,7 @@ type ModuleApi<E extends EventMap = EventMap> = {
137
151
  * The plugin that assembles an app from modules: `bus.use(modulePlugin(modules))`
138
152
  * mounts `modules` at once, in the order given, and returns `mount`, `unmount`,
139
153
  * `isMounted`, `dispose` and `commands` for the modules that come and go later. The bus runs the commands that the
140
- * modules bind: if `createCommands(bus)` was called before, that registry is
154
+ * modules bind: if `bus.use(commandsPlugin())` was called before, that registry is
141
155
  * used, otherwise the app attaches its own, as `app.commands`.
142
156
  *
143
157
  * A module is known by its `name`: mounting a module whose name is taken
@@ -164,4 +178,4 @@ type ModuleApi<E extends EventMap = EventMap> = {
164
178
  */
165
179
  declare const modulePlugin: <E extends EventMap>(modules?: readonly Module<E>[]) => (bus: Bus<E>) => ModuleApi<E>;
166
180
  //#endregion
167
- export { modulePlugin as a, createCommand as c, createModule as i, createCommands as l, ModuleApi as n, Binding as o, ModuleContext as r, bindHandler as s, Module as t };
181
+ export { modulePlugin as a, bindHandler as c, createModule as i, commandsPlugin as l, ModuleApi as n, Binding as o, ModuleContext as r, MadeCommand as s, Module as t, createCommand as u };
@@ -1,29 +1,3 @@
1
- //#region src/core/types.d.ts
2
- type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
3
- type EventMap = Record<string, unknown>;
4
- type Keys<E> = keyof E & string;
5
- type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
6
- type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command";
7
- type Phase = "start" | "done" | "error" | "cancel" | "drop";
8
- type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
9
- id: number;
10
- parent?: number;
11
- type: K;
12
- effect: EffectName;
13
- phase: Phase;
14
- payload: E[K];
15
- error?: unknown;
16
- }; }[Keys<E>];
17
- /**
18
- * The contract of every trace logger: receives each task phase of a bus.
19
- * Adapters in `nanoeffects/trace` are factories that return one; pass it
20
- * through `createTracer` to `createBus({ trace })`.
21
- */
22
- type TraceLogger<E = Record<string, unknown>> = (event: TraceEvent<E>) => void;
23
- /** One logger or several; a throwing logger never breaks the task or the others. */
24
- type Trace<E = Record<string, unknown>> = TraceLogger<E> | readonly TraceLogger<E>[];
25
- type UnsubscribeCallback = () => void;
26
- //#endregion
27
1
  //#region src/core/store.d.ts
28
2
  declare const anyEventType = "*";
29
3
  //#endregion
@@ -68,27 +42,35 @@ type Action<E extends EventMap> = {
68
42
  type: EventKey<E>;
69
43
  payload: EventPayload<E>;
70
44
  };
71
- type WithPayload<E extends EventMap, K extends EventKey<E>> = undefined extends E[K] ? {
72
- type: K;
73
- payload?: E[K];
74
- } : {
75
- type: K;
76
- payload: E[K];
77
- };
78
45
  type EventLike<E extends EventMap> = { [K in EventKey<E>]: WithPayload<E, K>; }[Keys<E>];
79
46
  /**
80
- * A typed request for a result. `bus.emit(command, payload)` runs the handler
81
- * of the command as a task and returns what it returns. Made by
47
+ * Brands `{ type, payload }` from a command call so `emit` can run the command.
48
+ * Not enumerable on the object.
49
+ */
50
+ declare const commandCall: unique symbol;
51
+ /**
52
+ * What `command(payload)` returns: an action-shaped value that `emit` runs as
53
+ * that command. A plain `{ type, payload }` without this brand is notify-only.
54
+ */
55
+ type CommandCall<P = unknown, R = unknown> = {
56
+ type: string;
57
+ payload: P;
58
+ readonly [commandCall]: Command<P, R>;
59
+ };
60
+ /**
61
+ * A typed request for a result. Calling it builds `{ type, payload }` like
62
+ * `createAction`; `bus.emit(command(payload))` (or `bus.emit(command, payload)`)
63
+ * runs the handler as a task and returns what it returns. Made by
82
64
  * `createCommand` in `nanoeffects/actions`.
83
65
  */
84
66
  type Command<P = never, R = unknown> = {
85
- (payload: P, ctx?: never): R;
67
+ (payload: P): CommandCall<P, R>;
86
68
  readonly type: string;
87
69
  /** Wraps the handler that really runs, e.g. to route its outcome. */
88
70
  readonly wrap?: (run: (payload: never, ctx: never) => unknown) => (payload: never, ctx: never) => unknown;
89
71
  };
90
72
  /**
91
- * What the bus needs to run commands. The implementation, `createCommands` in
73
+ * What the bus needs to run commands. The implementation, `commandsPlugin` in
92
74
  * `nanoeffects/actions`, holds the handlers bound to commands and runs the
93
75
  * right one, so a bus without `commands` carries none of that.
94
76
  */
@@ -96,11 +78,13 @@ interface Commands {
96
78
  run(command: Command, payload: unknown, ctx: unknown): unknown;
97
79
  }
98
80
  /** Anything `emit` takes as its first argument: an event type, an action or a command. */
99
- type Emittable<E extends EventMap> = EventKey<E> | Command | EventLike<E>;
81
+ type Emittable<E extends EventMap> = EventKey<E> | Command | CommandCall | EventLike<E>;
100
82
  type Emit<E extends EventMap> = {
101
83
  <K extends EventKey<E>>(event: K, ...payload: PayloadOf<E[K]>): void;
102
- <K extends EventKey<E>, R>(event: Handler<E, R, K>, ...payload: PayloadOf<E[K]>): R;
84
+ /** Before Handler: a command is callable too, and must return its result type. */
103
85
  <P, R>(command: Command<P, R>, ...payload: PayloadOf<P>): R;
86
+ <P, R>(call: CommandCall<P, R>): R;
87
+ <K extends EventKey<E>, R>(event: Handler<E, R, K>, ...payload: PayloadOf<E[K]>): R;
104
88
  (event: EventLike<E>): void;
105
89
  };
106
90
  type On<E extends EventMap> = {
@@ -119,6 +103,8 @@ type On<E extends EventMap> = {
119
103
  }, fn: Task<E[K], E>): UnsubscribeCallback;
120
104
  };
121
105
  type Off<E extends EventMap> = {
106
+ /** Removes every listener of every event (including `"*"`). */
107
+ (): void;
122
108
  (event: AnyEvent): void;
123
109
  (event: AnyEvent, fn: Task<EventPayload<E>, E>): void;
124
110
  <K extends EventKey<E>>(event: K): void;
@@ -173,6 +159,11 @@ type Context<E extends EventMap> = EventLike<E> & ContextOf<E> & {
173
159
  };
174
160
  interface Bus<E extends EventMap> {
175
161
  on: On<E>;
162
+ /**
163
+ * Like `on`, but the handler runs at most once: it is removed before it is
164
+ * invoked, so a nested emit of the same event does not re-enter it.
165
+ */
166
+ once: On<E>;
176
167
  off: Off<E>;
177
168
  emit: Emit<E>;
178
169
  /**
@@ -183,7 +174,7 @@ interface Bus<E extends EventMap> {
183
174
  use<R>(plugin: (bus: Bus<E>) => R): R;
184
175
  /** `BusOptions.context` and `.trace`, and `commands`, for what makes tasks of its own, like `modulePlugin`. */
185
176
  readonly context?: ContextOption<E> | undefined;
186
- /** What runs the commands; `createCommands(bus)` and `modulePlugin` set it. Without one a command runs its own handler. */
177
+ /** What runs the commands; `commandsPlugin` and `modulePlugin` set it. Without one a command runs its own handler. */
187
178
  commands?: Commands | undefined;
188
179
  readonly trace?: Tracer | undefined;
189
180
  }
@@ -223,7 +214,40 @@ type BusOptions<E extends EventMap> = {
223
214
  };
224
215
  declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
225
216
  //#endregion
226
- //#region src/actions/action.d.ts
217
+ //#region src/core/types.d.ts
218
+ type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
219
+ type EventMap = Record<string, unknown>;
220
+ type Keys<E> = keyof E & string;
221
+ type Task<P, E extends EventMap, R = unknown> = (payload: P, ctx: Context<E>) => R;
222
+ type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "run" | "all" | "race" | "retry" | "timeout" | "poll" | "take" | "queue" | "allSettled" | "command";
223
+ type Phase = "start" | "done" | "error" | "cancel" | "drop";
224
+ type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
225
+ id: number;
226
+ parent?: number;
227
+ type: K;
228
+ effect: EffectName;
229
+ phase: Phase;
230
+ payload: E[K];
231
+ error?: unknown;
232
+ }; }[Keys<E>];
233
+ /**
234
+ * The contract of every trace logger: receives each task phase of a bus.
235
+ * Adapters in `nanoeffects/trace` are factories that return one; pass it
236
+ * through `createTracer` to `createBus({ trace })`.
237
+ */
238
+ type TraceLogger<E = Record<string, unknown>> = (event: TraceEvent<E>) => void;
239
+ /** One logger or several; a throwing logger never breaks the task or the others. */
240
+ type Trace<E = Record<string, unknown>> = TraceLogger<E> | readonly TraceLogger<E>[];
241
+ type UnsubscribeCallback = () => void;
242
+ //#endregion
243
+ //#region src/core/action-creator.d.ts
244
+ type WithPayload<E extends EventMap, K extends Keys<E>> = undefined extends E[K] ? {
245
+ type: K;
246
+ payload?: E[K];
247
+ } : {
248
+ type: K;
249
+ payload: E[K];
250
+ };
227
251
  type Absent<P> = [P] extends [void] ? undefined : P;
228
252
  type Made<P, T extends string> = WithPayload<{ [K in T]: Absent<P>; }, T>;
229
253
  declare const free: unique symbol;
@@ -267,37 +291,5 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
267
291
  }): action is Made<P, T>;
268
292
  toString(): T;
269
293
  }
270
- /**
271
- * Creates an action creator, as in Redux Toolkit.
272
- *
273
- * - `createAction("user/loaded")` needs no generics: the payload type comes
274
- * from the event map of the bus that the action goes to, and the literal
275
- * type of the action is kept.
276
- * - `createAction<User>("user/loaded")` gives the payload type, for a bus
277
- * without an event map or to check the calls of the creator. The type of
278
- * the action is then `string`; to keep the literal, give it as the second
279
- * generic: `createAction<User, "user/loaded">("user/loaded")`.
280
- * - With `prepare` the arguments of the creator can differ from the payload,
281
- * and both types are inferred.
282
- *
283
- * @example
284
- * ```ts
285
- * const added = createAction<number>("counter/added");
286
- * added(2); // { type: "counter/added", payload: 2 }
287
- * added.type; // "counter/added"
288
- * added.match(action); // true for actions of this type
289
- *
290
- * const renamed = createAction("user/renamed", (id: string, name: string) => ({
291
- * payload: { id, name },
292
- * }));
293
- *
294
- * bus.emit(added(2));
295
- * bus.on(added, (n) => console.log(n));
296
- * ```
297
- */
298
- declare function createAction<P = Free, T extends string = string>(type: T): [P] extends [Free] ? FreeActionCreator<T> : ActionCreator<P, T>;
299
- declare function createAction<A extends unknown[], P, T extends string = string>(type: T, prepare: (...args: A) => {
300
- payload: P;
301
- }): ActionCreator<P, T, A>;
302
294
  //#endregion
303
- export { Keys as A, WithPayload as C, anyEventType as D, Tracer as E, TraceEvent as F, TraceLogger as I, UnsubscribeCallback as L, Phase as M, Task as N, EffectName as O, Trace as P, WithContext as S, createBus as T, EventPayload as _, AnyEvent as a, Off as b, Command as c, ContextOf as d, ContextOption as f, EventLike as g, EventKey as h, Action as i, PayloadOf as j, EventMap as k, Commands as l, Emittable as m, FreeActionCreator as n, Bus as o, Emit as p, createAction as r, BusOptions as s, ActionCreator as t, Context as u, Handler as v, WithType as w, On as x, HandlerRef as y };
295
+ export { Handler as A, ContextOf as C, EventKey as D, Emittable as E, WithType as F, commandCall as I, createBus as L, Off as M, On as N, EventLike as O, WithContext as P, Tracer as R, Context as S, Emit as T, Bus as _, EffectName as a, CommandCall as b, PayloadOf as c, Trace as d, TraceEvent as f, AnyEvent as g, Action as h, WithPayload as i, HandlerRef as j, EventPayload as k, Phase as l, UnsubscribeCallback as m, Free as n, EventMap as o, TraceLogger as p, FreeActionCreator as r, Keys as s, ActionCreator as t, Task as u, BusOptions as v, ContextOption as w, Commands as x, Command as y, anyEventType as z };
@@ -1,17 +1,66 @@
1
- import { L as UnsubscribeCallback, N as Task, c as Command, j as PayloadOf, k as EventMap, n as FreeActionCreator, o as Bus, r as createAction, t as ActionCreator, u as Context } from "./action-rqZEnRIp.js";
1
+ import { S as Context, _ as Bus, c as PayloadOf, m as UnsubscribeCallback, n as Free, o as EventMap, r as FreeActionCreator, t as ActionCreator, u as Task, y as Command } from "./action-creator-D48fp13T.js";
2
+ //#region src/actions/action.d.ts
3
+ /**
4
+ * Creates an action creator, as in Redux Toolkit.
5
+ *
6
+ * - `createAction("user/loaded")` needs no generics: the payload type comes
7
+ * from the event map of the bus that the action goes to, and the literal
8
+ * type of the action is kept.
9
+ * - `createAction<User>("user/loaded")` gives the payload type, for a bus
10
+ * without an event map or to check the calls of the creator. The type of
11
+ * the action is then `string`; to keep the literal, give it as the second
12
+ * generic: `createAction<User, "user/loaded">("user/loaded")`.
13
+ * - With `prepare` the arguments of the creator can differ from the payload,
14
+ * and both types are inferred.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const added = createAction<number>("counter/added");
19
+ * added(2); // { type: "counter/added", payload: 2 }
20
+ * added.type; // "counter/added"
21
+ * added.match(action); // true for actions of this type
22
+ *
23
+ * const renamed = createAction("user/renamed", (id: string, name: string) => ({
24
+ * payload: { id, name },
25
+ * }));
26
+ *
27
+ * bus.emit(added(2));
28
+ * bus.on(added, (n) => console.log(n));
29
+ * ```
30
+ */
31
+ export declare function createAction<P = Free, T extends string = string>(type: T): [P] extends [Free] ? FreeActionCreator<T> : ActionCreator<P, T>;
32
+ export declare function createAction<A extends unknown[], P, T extends string = string>(type: T, prepare: (...args: A) => {
33
+ payload: P;
34
+ }): ActionCreator<P, T, A>;
35
+ //#endregion
2
36
  //#region src/actions/command.d.ts
37
+ /** What `createCommand` returns: a command that also tells whether an action is of its type. */
38
+ type MadeCommand<P, R, T extends string> = Command<P, R> & {
39
+ readonly type: T;
40
+ /** Tells whether an action has the type of this command, and narrows its type. */
41
+ match(action: {
42
+ type: string;
43
+ payload?: unknown;
44
+ }): action is {
45
+ type: T;
46
+ payload: P;
47
+ };
48
+ };
3
49
  /**
4
- * Creates a command: a typed request for a result. `bus.emit(command, payload)`
5
- * runs its handler as a task, with a context, and returns what the handler
6
- * returns. Listeners of the command's type are told first, as for any event.
50
+ * Creates a command: a typed request for a result. Calling it builds
51
+ * `{ type, payload }` like `createAction`. `bus.emit(command(payload))` (or
52
+ * `bus.emit(command, payload)`) runs its handler as a task, with a context, and
53
+ * returns what the handler returns. Listeners of the command's type are told
54
+ * first, as for any event.
7
55
  *
8
56
  * The handler is optional. A command without one is only a contract, and the
9
57
  * bus gets its implementation from the `commands` registry (see
10
- * `createCommands` and `bindHandler`). A handler bound there wins over the one
58
+ * `commandsPlugin` and `bindHandler`). A handler bound there wins over the one
11
59
  * the command was created with, so a test can give a bus its own implementation.
12
60
  *
13
- * A handler can be wrapped in a policy, e.g. `latest(fn)`. Calling the command
14
- * directly, `command(payload)`, runs its own handler outside of any bus.
61
+ * A handler can be wrapped in a policy, e.g. `latest(fn)`.
62
+ * `command.match(action)` tells whether an action has the type of the command,
63
+ * as it does for an action creator.
15
64
  *
16
65
  * @example
17
66
  * ```ts
@@ -20,34 +69,33 @@ import { L as UnsubscribeCallback, N as Task, c as Command, j as PayloadOf, k as
20
69
  * );
21
70
  * const sendMail = createCommand<Mail, void>("mail/send"); // implemented elsewhere
22
71
  *
23
- * const commands = createCommands([bindHandler(sendMail, smtpSend)]);
24
- * const bus = createBus({ commands });
25
- * const user = await bus.emit(getUser, "1");
72
+ * const bus = createBus<Events>();
73
+ * bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
74
+ * const user = await bus.emit(getUser("1"));
26
75
  *
27
76
  * commands.handle(getUser, async () => fakeUser); // in a test
28
77
  * ```
29
78
  */
30
- export declare const createCommand: <P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>) => Command<P, R> & {
31
- readonly type: T;
32
- };
79
+ export declare const createCommand: <P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>) => MadeCommand<P, R, T>;
33
80
  /** A command (or its type) with the handler to bind to it; `bindHandler` makes one. */
34
81
  type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
35
82
  /**
36
- * Pairs a command with the handler to bind to it, for `createCommands`. It
83
+ * Pairs a command with the handler to bind to it, for `commandsPlugin`. It
37
84
  * checks that the handler fits the command.
38
85
  *
39
86
  * @example
40
87
  * ```ts
41
- * createCommands([bindHandler(sendMail, smtpSend)]);
88
+ * bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
42
89
  * ```
43
90
  */
44
91
  export declare const bindHandler: <P, R, E extends EventMap>(command: Command<P, R>, fn: Task<P, E, R>) => Binding<E>;
45
92
  /**
46
- * The handlers bound to commands of `bus`: it makes the registry, sets it as
47
- * the commands of the bus and returns it. Each bus has its own, so each test
48
- * can have its own implementation. `handle` binds more later and returns the
49
- * function that unbinds. A second `createCommands(bus)` replaces the registry
50
- * of that bus.
93
+ * The plugin that gives a bus the handlers bound to commands:
94
+ * `bus.use(commandsPlugin(bindings))` makes the registry, sets it as the
95
+ * commands of the bus and returns it. Each bus has its own, so each test can
96
+ * have its own implementation. `handle` binds more later and returns the
97
+ * function that unbinds. A second `commandsPlugin` on the same bus replaces
98
+ * the registry of that bus.
51
99
  *
52
100
  * What the bus runs for a command: the handler bound last, else the one the
53
101
  * command was created with, else it throws `No handler for command "..."`.
@@ -55,13 +103,13 @@ export declare const bindHandler: <P, R, E extends EventMap>(command: Command<P,
55
103
  * @example
56
104
  * ```ts
57
105
  * const bus = createBus<Events>();
58
- * const commands = createCommands(bus, [bindHandler(sendMail, smtpSend)]);
106
+ * const commands = bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
59
107
  *
60
108
  * const unbind = commands.handle(getUser, async () => fakeUser);
61
109
  * unbind(); // the command's own handler is back
62
110
  * ```
63
111
  */
64
- export declare const createCommands: <E extends EventMap>(bus: Bus<E>, bindings?: readonly Binding<E>[]) => {
112
+ export declare const commandsPlugin: <E extends EventMap>(bindings?: readonly Binding<E>[]) => (bus: Bus<E>) => {
65
113
  run: (command: Command, payload: unknown, ctx: unknown) => unknown;
66
114
  handle: {
67
115
  <P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
@@ -79,43 +127,43 @@ type Creator = {
79
127
  readonly type: string;
80
128
  };
81
129
  type Outcome = string | Creator;
82
- /** What `createJob` returns: the command of the job and the actions of its outcome. */
83
- type Job<P, R, T extends string, S extends Outcome, F extends Outcome> = {
84
- command: Command<P, Promise<Awaited<R> | undefined>> & {
85
- readonly type: T;
86
- };
130
+ /** What `createJob` returns: the command of the job, with its two actions as properties. */
131
+ type Job<P, R, T extends string, S extends Outcome, F extends Outcome> = MadeCommand<P, Promise<Awaited<R> | undefined>, T> & {
87
132
  /** Made from a string with the result as its payload, or the creator that was given. */
88
- successAction: S extends string ? ActionCreator<Awaited<R>, S> : S;
133
+ readonly success: S extends string ? ActionCreator<Awaited<R>, S> : S;
89
134
  /** Made from a string with the error as its payload, or the creator that was given. */
90
- failAction: F extends string ? ActionCreator<unknown, F> : F;
135
+ readonly fail: F extends string ? ActionCreator<unknown, F> : F;
91
136
  };
92
137
  /**
93
138
  * Creates a job: a command whose outcome is sent on as actions. When the
94
- * handler succeeds, `successAction(result)` is emitted on the bus, and when it
95
- * fails, `failAction(error)`. It is made for the case where nobody waits for
139
+ * handler succeeds, `job.success(result)` is emitted on the bus, and when it
140
+ * fails, `job.fail(error)`. It is made for the case where nobody waits for
96
141
  * the result and the bus carries it on, like `createAsyncThunk` or an effector
97
- * effect. It returns the three together: `{ command, successAction, failAction }`.
142
+ * effect. It returns the command, with the two actions on it: `job.success` and
143
+ * `job.fail`.
98
144
  *
99
145
  * `success` and `fail` are a type string, from which the job makes an action
100
146
  * creator with `createAction`, or an action creator that exists already, which
101
147
  * is used and returned as it is. A missing one is made with the type
102
148
  * `<type>/success` or `<type>/fail`.
103
149
  *
104
- * `bus.emit(command, payload)` returns a promise of the result. An error of the
105
- * handler always counts as handled: it goes to `failAction` and the promise
150
+ * `bus.emit(job(payload))` returns a promise of the result. An error of the
151
+ * handler always counts as handled: it goes to `job.fail` and the promise
106
152
  * resolves with `undefined`; a command is the tool for a result that must reject.
107
153
  * The actions are emitted as the task that ran the job, also for a handler bound
108
154
  * with `commands.handle`, and are skipped once the task is aborted. A missing
109
155
  * handler is not an outcome: `emit` throws `MissingHandlerError`. Calling the
110
- * command directly runs only its handler.
156
+ * job builds `{ type, payload }` like a command; it does not run the handler.
111
157
  *
112
158
  * @example
113
159
  * ```ts
114
- * const { command: loadUser, successAction: userLoaded, failAction: userFailed } =
115
- * createJob("user/load", fetchUser, { success: "user/loaded", fail: "user/failed" });
160
+ * const loadUser = createJob("user/load", fetchUser, {
161
+ * success: "user/loaded",
162
+ * fail: "user/failed",
163
+ * });
116
164
  *
117
- * bus.on(userLoaded, (user) => render(user));
118
- * bus.emit(loadUser, "1"); // userLoaded(user) or userFailed(error) comes later
165
+ * bus.on(loadUser.success, (user) => render(user));
166
+ * bus.emit(loadUser("1")); // loadUser.success(user) or loadUser.fail(error) comes later
119
167
  * ```
120
168
  */
121
169
  export declare const createJob: <P = void, R = void, T extends string = string, E extends EventMap = EventMap, S extends Outcome = `${T}/success`, F extends Outcome = `${T}/fail`>(type: T, handler?: Task<P, E, R>, outcomes?: {
@@ -176,7 +224,7 @@ type Module<E extends EventMap = EventMap> = {
176
224
  * ```
177
225
  */
178
226
  export declare const createModule: <E extends EventMap = EventMap>(name: string, setup: (m: ModuleContext<E>) => void) => Module<E>;
179
- type Registry<E extends EventMap> = ReturnType<typeof createCommands<E>>;
227
+ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<E>>>;
180
228
  /** What `modulePlugin` returns. */
181
229
  type ModuleApi<E extends EventMap = EventMap> = {
182
230
  /** The registry of command handlers of the bus: the one it was made with, or the app's own. */
@@ -192,7 +240,7 @@ type ModuleApi<E extends EventMap = EventMap> = {
192
240
  * The plugin that assembles an app from modules: `bus.use(modulePlugin(modules))`
193
241
  * mounts `modules` at once, in the order given, and returns `mount`, `unmount`,
194
242
  * `isMounted`, `dispose` and `commands` for the modules that come and go later. The bus runs the commands that the
195
- * modules bind: if `createCommands(bus)` was called before, that registry is
243
+ * modules bind: if `bus.use(commandsPlugin())` was called before, that registry is
196
244
  * used, otherwise the app attaches its own, as `app.commands`.
197
245
  *
198
246
  * A module is known by its `name`: mounting a module whose name is taken
@@ -219,4 +267,4 @@ type ModuleApi<E extends EventMap = EventMap> = {
219
267
  */
220
268
  export declare const modulePlugin: <E extends EventMap>(modules?: readonly Module<E>[]) => (bus: Bus<E>) => ModuleApi<E>;
221
269
  //#endregion
222
- export { type ActionCreator, type Binding, type FreeActionCreator, type Job, type Module, type ModuleApi, type ModuleContext, createAction };
270
+ export type { ActionCreator, Binding, FreeActionCreator, Job, Module, ModuleApi, ModuleContext };
@@ -1 +1 @@
1
- import{i as e,n as t,s as n}from"./context-yAWj0BFZ.js";import{t as r}from"./event-0RIBGYqS.js";function i(e,t){return Object.assign((...n)=>({type:e,payload:t?t(...n).payload:n[0]}),{type:e,match:t=>t.type===e,toString:()=>e})}var a=class extends Error{};const o=(e,n)=>Object.assign((r,i)=>{if(!n)throw new a(`No handler for command "${e}"`);return n(r,i??t({event:{type:e,payload:r}}).ctx)},{type:e}),s=(e,t)=>[e,t],c=(e,t=[])=>{let n=/* @__PURE__ */ new Map,i=(e,t)=>{let r={fn:t};return n.set(e,[...n.get(e)??[],r]),()=>{let t=(n.get(e)??[]).filter(e=>e!==r);t.length>0?n.set(e,t):n.delete(e)}};function a(e,t){if(t)return i(r(e),t);let n=e.map(([e,t])=>i(r(e),t));return()=>{for(let e of n)e()}}a(t);let o={run:(e,t,r)=>{let i=(n.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,r])},handle:a};return e.commands=o,o},l=e=>typeof e==`string`?i(e):e,u=(e,t,n)=>{let r=e.emit;r(Reflect.apply(t,null,[n]))},d=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof a)throw e;return Promise.reject(e)}},f=(e,t,n={})=>{let r=o(e,t),i=l(n.success??`${e}/success`),a=l(n.fail??`${e}/fail`),s=(e,t,n)=>{let r=n;return d(()=>Reflect.apply(e,null,[t,n])).then(e=>(u(r,i,e),e),e=>{u(r,a,e)})};return{command:Object.assign((e,t)=>t?s(r,e,t):d(()=>r(e)),{type:e,wrap:e=>(t,n)=>s(e,t,n)}),successAction:i,failAction:a}},p=(e,t)=>({name:e,setup:t}),m=(r=[])=>i=>{let a=i.commands??c(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `createCommands()`");return Reflect.apply(a.handle,null,e)}},s=t({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace}),l=t=>{let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return{mount:a=>{let s=r.get(a);if(s)return s;let c=i.get(a.name);c&&r.get(c)?.();let u=e(t,a.name),d=u.ctx,f=l(d),p=()=>{r.delete(a),i.get(a.name)===a&&i.delete(a.name),d.abort(),u.unlink()};r.set(a,p),i.set(a.name,a);let m=(e,t)=>{let r=Reflect.apply(o.handle,null,[e,t]);return n(d,r),r},h=(...e)=>{let t=e.map(e=>typeof e==`function`?m(e,e):f.mount(e));return()=>{for(let e of t)e()}},g=(e,...t)=>{d.run(e,...t).catch(e=>{if(!d.signal.aborted)throw e})};try{a.setup(Object.assign(d,{handle:m,use:h,spawn:g}))}catch(e){throw p(),e}return p},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},u=l(s.ctx);for(let e of r)u.mount(e);return{commands:a,mount:e=>(s.ctx.signal.throwIfAborted(),u.mount(e)),unmount:u.unmount,isMounted:u.isMounted,dispose:()=>s.ctx.abort()}};export{s as bindHandler,i as createAction,o as createCommand,c as createCommands,f as createJob,p as createModule,m as modulePlugin};
1
+ import{i as e,n as t,s as n}from"./context-yAWj0BFZ.js";import{a as r,r as i}from"./bus-B12SvxLv.js";function a(e,t){return Object.assign((...n)=>({type:e,payload:t?t(...n).payload:n[0]}),{type:e,match:t=>t.type===e,toString:()=>e})}var o=class extends Error{};const s=(e,t)=>{let n=t=>t.type===e;function r(n,r){if(typeof r==`object`){if(!t)throw new o(`No handler for command "${e}"`);return t(n,r)}return i(a,e,n)}let a=Object.assign(r,{type:e,match:n});return a},c=(e,t)=>[e,t],l=(e=[])=>t=>{let n=/* @__PURE__ */ new Map,i=(e,t)=>{let r={fn:t};return n.set(e,[...n.get(e)??[],r]),()=>{let t=(n.get(e)??[]).filter(e=>e!==r);t.length>0?n.set(e,t):n.delete(e)}};function a(e,t){if(t)return i(r(e),t);let n=e.map(([e,t])=>i(r(e),t));return()=>{for(let e of n)e()}}a(e);let o={run:(e,t,r)=>{let i=(n.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,r])},handle:a};return t.commands=o,o},u=e=>typeof e==`string`?a(e):e,d=(e,t,n)=>{let r=e.emit;r(Reflect.apply(t,null,[n]))},f=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof o)throw e;return Promise.reject(e)}},p=(e,t,n={})=>{let r=s(e,t),a=u(n.success??`${e}/success`),o=u(n.fail??`${e}/fail`),c=(e,t,n)=>{let r=n;return f(()=>Reflect.apply(e,null,[t,n])).then(e=>(d(r,a,e),e),e=>{d(r,o,e)})},l=e=>(t,n)=>c(e,t,n);function p(t,n){return typeof n==`object`?c(r,t,n):i(m,e,t)}let m=Object.assign(p,{type:e,match:r.match,wrap:l,success:a,fail:o});return m},m=(e,t)=>({name:e,setup:t}),h=(r=[])=>i=>{let a=i.commands??l()(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=t({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace}),c=t=>{let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return{mount:a=>{let s=r.get(a);if(s)return s;let l=i.get(a.name);l&&r.get(l)?.();let u=e(t,a.name),d=u.ctx,f=c(d),p=()=>{r.delete(a),i.get(a.name)===a&&i.delete(a.name),d.abort(),u.unlink()};r.set(a,p),i.set(a.name,a);let m=(e,t)=>{let r=Reflect.apply(o.handle,null,[e,t]);return n(d,r),r},h=(...e)=>{let t=e.map(e=>typeof e==`function`?m(e,e):f.mount(e));return()=>{for(let e of t)e()}},g=(e,...t)=>{d.run(e,...t).catch(e=>{if(!d.signal.aborted)throw e})};try{a.setup(Object.assign(d,{handle:m,use:h,spawn:g}))}catch(e){throw p(),e}return p},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},u=c(s.ctx);for(let e of r)u.mount(e);return{commands:a,mount:e=>(s.ctx.signal.throwIfAborted(),u.mount(e)),unmount:u.unmount,isMounted:u.isMounted,dispose:()=>s.ctx.abort()}};export{c as bindHandler,l as commandsPlugin,a as createAction,s as createCommand,p as createJob,m as createModule,h as modulePlugin};
@@ -0,0 +1 @@
1
+ import{a as e,c as t,n,r}from"./context-yAWj0BFZ.js";import{n as i}from"./promise-CSLpzwSR.js";const a=e=>typeof e==`string`?e:e.type,o=(e,t)=>typeof e==`object`?e.payload:t,s=`*`,c=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{for(let t of Reflect.ownKeys(e))delete e[t];for(let e of Reflect.ownKeys(t))delete t[e]}}},l=Symbol(`nanoeffects.commandCall`),u=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,l,{value:e,enumerable:!1}),r},d=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&l in e)return e[l]},f=(e,t,n)=>Reflect.apply(e,null,[t,n]),p=(s={})=>{let l=c(),u=(e,t)=>l.add(a(e),t),p=(e,t)=>{let n=u(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(a(e),t)},h=(e,a)=>{let{onError:o}=s,{ctx:c}=n({event:a,bus:g,tracer:s.trace,parent:{ref:r()}});if(!o){e(a.payload,c);return}let l=e=>{try{o(e,a)}catch(e){t(`onError failed`,e)}};try{let t=e(a.payload,c);i(t)&&Promise.resolve(t).catch(l)}catch(e){l(e)}},g={on:u,once:p,off:m,emit:(t,i)=>{let c=a(t),u=o(t,i),p={type:c,payload:u},m=d(t),_=[...l.get(c),...l.get(`*`)];_.length===0&&!m&&s.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:t}=n({event:p,bus:g,tracer:s.trace,parent:{ref:r()}}),i=g.commands?.run??f;return e(t,`command`,()=>i(m,u,t))}},use:e=>e(g),context:s.context,trace:s.trace};return g};export{a,s as i,p as n,u as r,l as t};
@@ -1,4 +1,4 @@
1
- import { A as Keys, N as Task, k as EventMap, u as Context } from "./action-rqZEnRIp.js";
1
+ import { S as Context, o as EventMap, s as Keys, u as Task } from "./action-creator-D48fp13T.js";
2
2
  //#region src/utils/delay.d.ts
3
3
  /**
4
4
  * Resolves after `ms`, or rejects early if `ctx.signal` aborts. `ms` can be a
@@ -1,2 +1,2 @@
1
- import { A as Keys, C as WithPayload, D as anyEventType, E as Tracer, F as TraceEvent, I as TraceLogger, L as UnsubscribeCallback, M as Phase, N as Task, O as EffectName, P as Trace, S as WithContext, T as createBus, _ as EventPayload, a as AnyEvent, b as Off, c as Command, d as ContextOf, f as ContextOption, g as EventLike, h as EventKey, i as Action, j as PayloadOf, k as EventMap, l as Commands, m as Emittable, o as Bus, p as Emit, s as BusOptions, u as Context, v as Handler, w as WithType, x as On, y as HandlerRef } from "./action-rqZEnRIp.js";
2
- export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type Commands, type Context, type ContextOf, type ContextOption, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, createBus };
1
+ import { A as Handler, C as ContextOf, D as EventKey, E as Emittable, F as WithType, I as commandCall, L as createBus, M as Off, N as On, O as EventLike, P as WithContext, R as Tracer, S as Context, T as Emit, _ as Bus, a as EffectName, b as CommandCall, c as PayloadOf, d as Trace, f as TraceEvent, g as AnyEvent, h as Action, i as WithPayload, j as HandlerRef, k as EventPayload, l as Phase, m as UnsubscribeCallback, o as EventMap, p as TraceLogger, s as Keys, u as Task, v as BusOptions, w as ContextOption, x as Commands, y as Command, z as anyEventType } from "./action-creator-D48fp13T.js";
2
+ export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, createBus };
@@ -1 +1 @@
1
- export{n as anyEventType,t as createBus}from"./bus-Dx0l9X6h.js";
1
+ export{i as anyEventType,t as commandCall,n as createBus}from"./bus-B12SvxLv.js";
@@ -1,4 +1,4 @@
1
- import { N as Task, k as EventMap } from "./action-rqZEnRIp.js";
1
+ import { o as EventMap, u as Task } from "./action-creator-D48fp13T.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 { k as EventMap, o as Bus, s as BusOptions } from "./action-rqZEnRIp.js";
1
+ import { _ as Bus, o as EventMap, v as BusOptions } from "./action-creator-D48fp13T.js";
2
2
  //#region src/store/redux/middleware.d.ts
3
3
  /** What Redux passes through a middleware: an action is a plain object with a `type`. */
4
4
  type ReduxAction = {
@@ -1 +1 @@
1
- import{c as e}from"./context-yAWj0BFZ.js";import{t}from"./bus-Dx0l9X6h.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware};
1
+ import{c as e}from"./context-yAWj0BFZ.js";import{n as t}from"./bus-B12SvxLv.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware};
@@ -1,4 +1,4 @@
1
- import { A as Keys, k as EventMap, o as Bus } from "./action-rqZEnRIp.js";
1
+ import { _ as Bus, o as EventMap, s as Keys } from "./action-creator-D48fp13T.js";
2
2
  //#region src/observable.d.ts
3
3
  declare global {
4
4
  interface SymbolConstructor {