nanoeffects 0.26.0 → 0.28.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.
- package/README.md +85 -30
- package/dist/{action-creator-Bpa8BUS9.d.ts → action-creator-CcAEvUnw.d.ts} +90 -23
- package/dist/actions.d.ts +54 -21
- package/dist/actions.js +1 -1
- package/dist/bus-DlpEluzd.js +1 -0
- package/dist/{context-types-BKIH5a8s.d.ts → context-types-hCKgU8sC.d.ts} +1 -1
- package/dist/context.d.ts +2 -2
- package/dist/dev.d.ts +2 -2
- package/dist/dev.js +1 -1
- package/dist/effects.d.ts +2 -2
- package/dist/event-DVcW0mME.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/match.d.ts +1 -1
- package/dist/{module-B6rg5NIb.d.ts → module-C_oEXw1n.d.ts} +40 -57
- package/dist/notrace/{action-creator-D2CotugT.d.ts → action-creator-DxOvVo8I.d.ts} +90 -23
- package/dist/notrace/actions.d.ts +114 -98
- package/dist/notrace/actions.js +1 -1
- package/dist/notrace/bus-DmKn4SDD.js +1 -0
- package/dist/notrace/effects.d.ts +2 -2
- package/dist/notrace/index.d.ts +2 -2
- package/dist/notrace/index.js +1 -1
- package/dist/notrace/{plugin-Dz6hq8Jg.d.ts → plugin-lJjjd-SN.d.ts} +1 -1
- package/dist/notrace/policies.d.ts +1 -1
- package/dist/notrace/policies.js +1 -1
- package/dist/notrace/redux.d.ts +1 -1
- package/dist/observable.d.ts +6 -6
- package/dist/oop.d.ts +2 -2
- package/dist/oop.js +1 -1
- package/dist/{plugin-D-j1DarG.d.ts → plugin-CuvIgjnX.d.ts} +2 -2
- package/dist/policies.d.ts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/redux.d.ts +1 -1
- package/dist/scope.d.ts +2 -2
- package/dist/signal.d.ts +1 -1
- package/dist/signal.js +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/{types-Bkuhnkq6.d.ts → types-FV8fuvI9.d.ts} +2 -2
- package/dist/vue.d.ts +1 -1
- package/dist/{with-policy-BeH8wCkX.d.ts → with-policy-3bhFLEXs.d.ts} +1 -1
- package/docs/README.md +5 -4
- package/docs/actions.md +94 -53
- package/docs/chat-example.md +8 -8
- package/docs/chat-widget.md +135 -0
- package/docs/context.md +1 -1
- package/docs/errors.md +1 -1
- package/docs/guide.md +26 -26
- package/docs/hmr.md +1 -1
- package/docs/motivation.md +10 -4
- package/docs/oop.md +1 -1
- package/docs/package.md +2 -2
- package/docs/plugins.md +23 -23
- package/docs/query-libraries.md +14 -14
- package/docs/scope.md +22 -22
- package/docs/server.md +12 -12
- package/docs/stability.md +2 -2
- package/docs/starter.md +3 -3
- package/docs/tracing.md +5 -5
- package/docs/typescript.md +16 -16
- package/llms-full.txt +380 -194
- package/llms.txt +3 -2
- package/package.json +5 -4
- package/dist/bus-hHp-T7JV.js +0 -1
- package/dist/event-0RIBGYqS.js +0 -1
- package/dist/notrace/bus-BdyvumpX.js +0 -1
- package/dist/notrace/promise-CSLpzwSR.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as BoundOf } from "./plugin-
|
|
1
|
+
import { B as Task, F as commandCall, L as EventMap, V as UnsubscribeCallback, _ as Command, c as WithScope, d as Effects, h as Bus, i as FreeActionCreator, n as Call, o as Scope, p as Actions, r as Free, s as WithFields, t as ActionCreator, v as CommandCall, w as EventKey, y as Context, z as PayloadOf } from "./action-creator-DxOvVo8I.js";
|
|
2
|
+
import { t as BoundOf } from "./plugin-lJjjd-SN.js";
|
|
3
3
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
4
4
|
//#region src/scope/types.d.ts
|
|
5
5
|
/**
|
|
@@ -23,48 +23,6 @@ type FieldsOfScope<E extends EventMap, S extends Scope> = [keyof S] extends [nev
|
|
|
23
23
|
*/
|
|
24
24
|
type Scoped<E extends EventMap, S extends Scope> = WithFields<E, FieldsOfScope<E, S>>;
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/actions/action.d.ts
|
|
27
|
-
type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
|
|
28
|
-
/**
|
|
29
|
-
* Creates an action creator, as in Redux Toolkit.
|
|
30
|
-
*
|
|
31
|
-
* - `createAction("user/loaded")` needs no generics: the payload type comes
|
|
32
|
-
* from the event map of the bus that the action goes to, and the literal
|
|
33
|
-
* type of the action is kept.
|
|
34
|
-
* - `createAction<User>("user/loaded")` gives the payload type, for a bus
|
|
35
|
-
* without an event map or to check the calls of the creator. The type of
|
|
36
|
-
* the action is then `string`; to keep the literal, give it as the second
|
|
37
|
-
* generic: `createAction<User, "user/loaded">("user/loaded")`.
|
|
38
|
-
* - With `prepare` the arguments of the creator can differ from the payload,
|
|
39
|
-
* and both types are inferred.
|
|
40
|
-
* - A scope as the last argument, `{ cache, $effects: { race } }`, gives the
|
|
41
|
-
* listeners of its calls those context fields; it works on a bus that uses `scopePlugin`
|
|
42
|
-
* from `nanoeffects/scope` and is ignored on any other.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const added = createAction<number>("counter/added");
|
|
47
|
-
* added(2); // { type: "counter/added", payload: 2 }
|
|
48
|
-
* added.type; // "counter/added"
|
|
49
|
-
* added.match(action); // true for actions of this type
|
|
50
|
-
*
|
|
51
|
-
* const renamed = createAction("user/renamed", (id: string, name: string) => ({
|
|
52
|
-
* payload: { id, name },
|
|
53
|
-
* }));
|
|
54
|
-
*
|
|
55
|
-
* bus.emit(added(2));
|
|
56
|
-
* bus.on(added, (n) => console.log(n));
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
export declare function createAction<P = Free, T extends string = string>(type: T): [P] extends [Free] ? FreeActionCreator<T> : ActionCreator<P, T>;
|
|
60
|
-
export declare function createAction<A extends unknown[], P, T extends string = string>(type: T, prepare: (...args: A) => {
|
|
61
|
-
payload: P;
|
|
62
|
-
}): ActionCreator<P, T, A>;
|
|
63
|
-
export declare function createAction<P = Free, T extends string = string, S extends Scope = Record<never, never>>(type: T, scope: S): ScopedCreator<P, T, FieldsOfScope<EventMap, S>>;
|
|
64
|
-
export declare function createAction<A extends unknown[], P, T extends string, S extends Scope>(type: T, prepare: (...args: A) => {
|
|
65
|
-
payload: P;
|
|
66
|
-
}, scope: S): ActionCreator<P, T, A, FieldsOfScope<EventMap, S>> & WithScope<FieldsOfScope<EventMap, S>>;
|
|
67
|
-
//#endregion
|
|
68
26
|
//#region src/actions/command.d.ts
|
|
69
27
|
/** What `createCommand` returns: a command that also tells whether an action is of its type. */
|
|
70
28
|
type MadeCommand<P, R, T extends string> = Command<P, R> & {
|
|
@@ -82,67 +40,46 @@ type MadeCommand<P, R, T extends string> = Command<P, R> & {
|
|
|
82
40
|
type CarryingCalls<Made, P, R, F> = [unknown] extends [F] ? Made : ((payload: P) => CommandCall<P, R> & WithScope<F>) & Made & WithScope<F>;
|
|
83
41
|
/** A command made with a scope: its calls carry the fields of that scope, for the checker. */
|
|
84
42
|
type ScopedCommand<P, R, T extends string, F> = ((payload: P) => CommandCall<P, R> & WithScope<F>) & MadeCommand<P, R, T> & WithScope<F>;
|
|
43
|
+
/** A command (or its type) with the handler to bind to it; `setHandler` makes one. */
|
|
44
|
+
type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
|
|
85
45
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* returns what the handler returns. Listeners of the command's type are told
|
|
90
|
-
* first, as for any event.
|
|
91
|
-
*
|
|
92
|
-
* The handler is optional. A command without one is only a contract, and the
|
|
93
|
-
* bus gets its implementation from the `commands` registry (see
|
|
94
|
-
* `commandsPlugin` and `bindHandler`). A handler bound there wins over the one
|
|
95
|
-
* the command was created with, so a test can give a bus its own implementation.
|
|
96
|
-
*
|
|
97
|
-
* A handler can be wrapped in a policy, e.g. `latest(fn)`.
|
|
98
|
-
* `command.match(action)` tells whether an action has the type of the command,
|
|
99
|
-
* as it does for an action creator.
|
|
100
|
-
*
|
|
101
|
-
* A scope as the third argument, `{ cache, $effects: { race } }`, puts those fields on
|
|
102
|
-
* the context of the handler and of the listeners of the command; the handler
|
|
103
|
-
* sees them typed. It works on a bus that uses `scopePlugin` from
|
|
104
|
-
* `nanoeffects/scope` and is ignored on any other.
|
|
46
|
+
* Pairs an action with the handler to bind to it, for `actionsPlugin`. For a
|
|
47
|
+
* command (an action made with a handler, or with a `Call` type) it checks that
|
|
48
|
+
* the handler fits; any other action is accepted with a handler of any payload.
|
|
105
49
|
*
|
|
106
50
|
* @example
|
|
107
51
|
* ```ts
|
|
108
|
-
*
|
|
109
|
-
* fetchUser(id, { signal }),
|
|
110
|
-
* );
|
|
111
|
-
* const sendMail = createCommand<Mail, void>("mail/send"); // implemented elsewhere
|
|
112
|
-
*
|
|
113
|
-
* const bus = createBus<Events>();
|
|
114
|
-
* bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
|
|
115
|
-
* const user = await bus.emit(getUser("1"));
|
|
116
|
-
*
|
|
117
|
-
* commands.handle(getUser, async () => fakeUser); // in a test
|
|
52
|
+
* bus.use(actionsPlugin([setHandler(sendMail, smtpSend)]));
|
|
118
53
|
* ```
|
|
119
54
|
*/
|
|
120
|
-
export declare function
|
|
121
|
-
export declare function
|
|
122
|
-
|
|
123
|
-
|
|
55
|
+
export declare function setHandler<P, R, E extends EventMap>(command: Command<P, R>, fn: Task<P, E, R>): Binding<E>;
|
|
56
|
+
export declare function setHandler<A extends {
|
|
57
|
+
readonly type: string;
|
|
58
|
+
}, E extends EventMap>(action: A, fn: LooseHandler<A, E>): Binding<E>;
|
|
124
59
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* bus.use(commandsPlugin([bindHandler(sendMail, smtpSend)]));
|
|
131
|
-
* ```
|
|
60
|
+
* The handler an action that is not a command can have: any. A command
|
|
61
|
+
* (a creator whose calls are command calls) is not accepted here, so its own
|
|
62
|
+
* overload checks the handler against its payload and result.
|
|
132
63
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
64
|
+
type LooseHandler<A, E extends EventMap> = A extends ((...args: never[]) => {
|
|
65
|
+
readonly [commandCall]: unknown;
|
|
66
|
+
}) ? never : Task<never, E, unknown>;
|
|
67
|
+
/** The registry of handlers that `actionsPlugin` returns: `run` for the bus, `handle` to bind more. */
|
|
68
|
+
interface Registry$1<E extends EventMap> extends Actions {
|
|
136
69
|
handle<P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
|
|
70
|
+
/** Also an action made without a handler: what is emitted for its type runs `fn` and returns its result. */
|
|
71
|
+
handle<A extends {
|
|
72
|
+
readonly type: string;
|
|
73
|
+
}>(action: A, fn: LooseHandler<A, E>): UnsubscribeCallback;
|
|
137
74
|
handle(type: string, fn: Task<never, E, unknown>): UnsubscribeCallback;
|
|
138
75
|
handle(bindings: readonly Binding<E>[]): UnsubscribeCallback;
|
|
139
76
|
}
|
|
140
77
|
/**
|
|
141
78
|
* The plugin that gives a bus the handlers bound to commands:
|
|
142
|
-
* `bus.use(
|
|
79
|
+
* `bus.use(actionsPlugin(bindings))` makes the registry, sets it as the
|
|
143
80
|
* commands of the bus and returns it. Each bus has its own, so each test can
|
|
144
81
|
* have its own implementation. `handle` binds more later and returns the
|
|
145
|
-
* function that unbinds. A second `
|
|
82
|
+
* function that unbinds. A second `actionsPlugin` on the same bus binds its
|
|
146
83
|
* list in the registry that is there and returns it, so the order of the
|
|
147
84
|
* plugins does not matter. A `commands` that is not such a registry (a custom
|
|
148
85
|
* runner) is replaced.
|
|
@@ -153,13 +90,88 @@ interface Registry$1<E extends EventMap> extends Commands {
|
|
|
153
90
|
* @example
|
|
154
91
|
* ```ts
|
|
155
92
|
* const bus = createBus<Events>();
|
|
156
|
-
* const commands = bus.use(
|
|
93
|
+
* const commands = bus.use(actionsPlugin([setHandler(sendMail, smtpSend)]));
|
|
157
94
|
*
|
|
158
95
|
* const unbind = commands.handle(getUser, async () => fakeUser);
|
|
159
96
|
* unbind(); // the command's own handler is back
|
|
160
97
|
* ```
|
|
161
98
|
*/
|
|
162
|
-
export declare const
|
|
99
|
+
export declare const actionsPlugin: <E extends EventMap>(bindings?: readonly Binding<E>[]) => (bus: Bus<E>) => Registry$1<E>;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/actions/action.d.ts
|
|
102
|
+
type Reserved = "handle" | "prepare";
|
|
103
|
+
type Made<P, T extends string> = [P] extends [Free] ? FreeActionCreator<T> : [P] extends [Call<infer Q, infer R>] ? MadeCommand<Q, R, T> : ActionCreator<P, T>;
|
|
104
|
+
type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
|
|
105
|
+
type ScopeOf<S> = Omit<S, Reserved>;
|
|
106
|
+
type PreparedCommand<P, R, T extends string, A extends unknown[], F> = ((...args: A) => ReturnType<MadeCommand<P, R, T>> & WithScope<F>) & Omit<MadeCommand<P, R, T>, never> & WithScope<F>;
|
|
107
|
+
/**
|
|
108
|
+
* Creates an action creator, as in Redux Toolkit. With a handler it makes a
|
|
109
|
+
* command: `bus.emit(getUser("1"))` runs the handler and returns its result.
|
|
110
|
+
*
|
|
111
|
+
* - `createAction("user/loaded")` needs no generics: the payload type comes
|
|
112
|
+
* from the event map of the bus that the action goes to, and the literal
|
|
113
|
+
* type of the action is kept. An action with no handler is an event.
|
|
114
|
+
* - `createAction<User>("user/loaded")` gives the payload type, for a bus
|
|
115
|
+
* without an event map or to check the calls of the creator. The type of
|
|
116
|
+
* the action is then `string`; to keep the literal, give it as the second
|
|
117
|
+
* generic: `createAction<User, "user/loaded">("user/loaded")`.
|
|
118
|
+
* - `createAction<Call<Mail, void>>("mail/send")` also says what a handler
|
|
119
|
+
* bound later returns; see `Call`.
|
|
120
|
+
* - A function as the second argument is the handler: it gets the payload and
|
|
121
|
+
* the context of the task, and `emit` returns what it returns. It can be
|
|
122
|
+
* wrapped in a policy, e.g. `latest(fn)`. A handler bound for the type in
|
|
123
|
+
* `actionsPlugin` wins over it.
|
|
124
|
+
* - The options object, as the second argument or the third after a handler,
|
|
125
|
+
* is `{ handle, prepare, ...scope }`: `handle` is the handler, `prepare`
|
|
126
|
+
* builds the payload from several arguments (both types are inferred), and
|
|
127
|
+
* every other field is the scope. A scope as the last argument,
|
|
128
|
+
* `{ cache, $effects: { race } }`, puts those fields on the context of the
|
|
129
|
+
* handler and of the listeners of its calls; it works on a bus that uses
|
|
130
|
+
* `scopePlugin` from `nanoeffects/scope` and is ignored on any other.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const added = createAction<number>("counter/added");
|
|
135
|
+
* added(2); // { type: "counter/added", payload: 2 }
|
|
136
|
+
* added.type; // "counter/added"
|
|
137
|
+
* added.match(action); // true for actions of this type
|
|
138
|
+
*
|
|
139
|
+
* const renamed = createAction("user/renamed", {
|
|
140
|
+
* prepare: (id: string, name: string) => ({ payload: { id, name } }),
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* const getUser = createAction("user/get", (id: string, { signal }) =>
|
|
144
|
+
* fetchUser(id, { signal }),
|
|
145
|
+
* );
|
|
146
|
+
* const user = await bus.emit(getUser("1"));
|
|
147
|
+
*
|
|
148
|
+
* bus.emit(added(2));
|
|
149
|
+
* bus.on(added, (n) => console.log(n));
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function createAction<P = Free, T extends string = string>(type: T): Made<P, T>;
|
|
153
|
+
export declare function createAction<P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler: Task<P, E, R>): MadeCommand<P, R, T>;
|
|
154
|
+
export declare function createAction<P, R, A extends unknown[], T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, ScopeOf<S>>, R>, options: {
|
|
155
|
+
prepare: (...args: A) => {
|
|
156
|
+
payload: P;
|
|
157
|
+
};
|
|
158
|
+
} & S): PreparedCommand<P, R, T, A, FieldsOfScope<EventMap, ScopeOf<S>>>;
|
|
159
|
+
export declare function createAction<P, R, A extends unknown[], T extends string, S extends Scope = Record<never, never>>(type: T, options: {
|
|
160
|
+
handle: Task<P, Scoped<EventMap, ScopeOf<S>>, R>;
|
|
161
|
+
prepare: (...args: A) => {
|
|
162
|
+
payload: P;
|
|
163
|
+
};
|
|
164
|
+
} & S): PreparedCommand<P, R, T, A, FieldsOfScope<EventMap, ScopeOf<S>>>;
|
|
165
|
+
export declare function createAction<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R>, scope: S): ScopedCommand<P, R, T, FieldsOfScope<EventMap, S>>;
|
|
166
|
+
export declare function createAction<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, options: {
|
|
167
|
+
handle: Task<P, Scoped<EventMap, ScopeOf<S>>, R>;
|
|
168
|
+
} & S): ScopedCommand<P, R, T, FieldsOfScope<EventMap, ScopeOf<S>>>;
|
|
169
|
+
export declare function createAction<A extends unknown[], P, T extends string, S extends Scope = Record<never, never>>(type: T, options: {
|
|
170
|
+
prepare: (...args: A) => {
|
|
171
|
+
payload: P;
|
|
172
|
+
};
|
|
173
|
+
} & S): ActionCreator<P, T, A, FieldsOfScope<EventMap, ScopeOf<S>>> & WithScope<FieldsOfScope<EventMap, ScopeOf<S>>>;
|
|
174
|
+
export declare function createAction<P = Free, T extends string = string, S extends Scope = Record<never, never>>(type: T, scope: S): ScopedCreator<P, T, FieldsOfScope<EventMap, S>>;
|
|
163
175
|
//#endregion
|
|
164
176
|
//#region src/actions/emitter.d.ts
|
|
165
177
|
/** What `emitterPlugin` adds to the bus. */
|
|
@@ -288,6 +300,10 @@ scope?: X) => CarryingCalls<Job<P, R, T, S, F, PE, CE>, P, Promise<Awaited<R> |
|
|
|
288
300
|
type ModuleContext<E extends EventMap = EventMap> = Context<E> & {
|
|
289
301
|
/** Binds the handler of a command, or a list of them; undone on unmount. */
|
|
290
302
|
handle<P, R>(command: Command<P, R>, fn: Task<P, E, R>): UnsubscribeCallback;
|
|
303
|
+
/** Also an action made without a handler: the handler answers it as it would a command. */
|
|
304
|
+
handle<A extends {
|
|
305
|
+
readonly type: string;
|
|
306
|
+
}>(action: A, fn: LooseHandler<A, E>): UnsubscribeCallback;
|
|
291
307
|
handle(type: string, fn: Task<never, E, unknown>): UnsubscribeCallback;
|
|
292
308
|
handle(bindings: readonly Binding<E>[]): UnsubscribeCallback;
|
|
293
309
|
/**
|
|
@@ -323,7 +339,7 @@ type Module<E extends EventMap = EventMap> = {
|
|
|
323
339
|
* ```ts
|
|
324
340
|
* export const userModule = createModule<Events>("user", (m) => {
|
|
325
341
|
* m.handle(getUser, fetchUser);
|
|
326
|
-
* m.handle([
|
|
342
|
+
* m.handle([setHandler(sendMail, smtpSend)]);
|
|
327
343
|
* m.use(authModule);
|
|
328
344
|
*
|
|
329
345
|
* m.on(loginRequested, (user, ctx) => ctx.emit(userLoaded(user)));
|
|
@@ -335,7 +351,7 @@ type Module<E extends EventMap = EventMap> = {
|
|
|
335
351
|
*/
|
|
336
352
|
export declare function createModule<E extends EventMap = EventMap>(name: string, setup: (m: ModuleContext<E>) => void): Module<E>;
|
|
337
353
|
export declare function createModule<E extends EventMap, S extends Scope = Record<never, never>>(name: string, setup: (m: ModuleContext<Scoped<E, S>>) => void, scope: S): Module<E>;
|
|
338
|
-
type Registry<E extends EventMap> = ReturnType<ReturnType<typeof
|
|
354
|
+
type Registry<E extends EventMap> = ReturnType<ReturnType<typeof actionsPlugin<E>>>;
|
|
339
355
|
/**
|
|
340
356
|
* The modules of an app as the plugins that report on them see them: the part
|
|
341
357
|
* of what `modulePlugin` returns that `devPlugin` wraps.
|
|
@@ -358,7 +374,7 @@ interface WithApp {
|
|
|
358
374
|
/** What `modulePlugin` returns. */
|
|
359
375
|
type ModuleApi<E extends EventMap = EventMap> = {
|
|
360
376
|
/** The registry of command handlers of the bus: the one it was made with, or the app's own. */
|
|
361
|
-
|
|
377
|
+
actions: Registry<E>;
|
|
362
378
|
/**
|
|
363
379
|
* Mounts modules, in the order given, and returns the function that unmounts them, last
|
|
364
380
|
* mounted first. A module that is mounted already is not run again. If one of them throws,
|
|
@@ -380,15 +396,15 @@ type ModuleApi<E extends EventMap = EventMap> = {
|
|
|
380
396
|
};
|
|
381
397
|
/**
|
|
382
398
|
* The plugin that assembles an app from modules: `bus.use(modulePlugin(modules))`
|
|
383
|
-
* returns `mount`, `unmount`, `isMounted`, `dispose` and `
|
|
399
|
+
* returns `mount`, `unmount`, `isMounted`, `dispose` and `actions` for the
|
|
384
400
|
* modules that come and go, and mounts `modules`, in the order given, on the
|
|
385
401
|
* first use of the app or of the bus: the first `bus.emit`, or the first call
|
|
386
402
|
* of one of its methods. By then every plugin is on the bus, so the plugins can
|
|
387
403
|
* be used in any order. The `on`, `once` and `off` calls made in between are
|
|
388
404
|
* held and made right after the modules, so the listeners of a module stay
|
|
389
405
|
* ahead of them. The bus runs the commands that the modules bind: the registry
|
|
390
|
-
* that the bus has is used (a later `
|
|
391
|
-
* app attaches its own, as `app.
|
|
406
|
+
* that the bus has is used (a later `actionsPlugin` binds in it), otherwise the
|
|
407
|
+
* app attaches its own, as `app.actions`. The app is also `bus.app`.
|
|
392
408
|
*
|
|
393
409
|
* A module is known by its `name`: mounting a module whose name is taken
|
|
394
410
|
* replaces the mounted one, which is unmounted first. That is what hot reload
|
|
@@ -413,7 +429,7 @@ type ModuleApi<E extends EventMap = EventMap> = {
|
|
|
413
429
|
* });
|
|
414
430
|
*
|
|
415
431
|
* bus.emit(getUser, "1");
|
|
416
|
-
* app.
|
|
432
|
+
* app.actions.handle(getUser, fakeUser); // in a test
|
|
417
433
|
* app.dispose();
|
|
418
434
|
* ```
|
|
419
435
|
*/
|
package/dist/notrace/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,i as t,l as n,n as r,s as i}from"./context-_HWcdjZf.js";import{n as a,r as o}from"./bus-
|
|
1
|
+
import{c as e,i as t,l as n,n as r,s as i}from"./context-_HWcdjZf.js";import{n as a,r as o}from"./bus-DmKn4SDD.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),m=e=>{let t=Object.assign(n=>a(t,e,n),{type:e});return t},h=e=>typeof e==`object`&&!!e&&Reflect.get(e,`signal`)instanceof AbortSignal&&typeof Reflect.get(e,`emit`)==`function`;var g=class extends Error{};function _(e,t,n){return v(e,t,n)}function v(e,t,n,r){let i=t=>t.type===e,o=e=>r?e.length===2&&h(e[1]):typeof e[1]==`object`;function s(...i){let[s,c]=i;if(o(i)){if(!t)throw new g(`No handler for command "${e}"`);return t(s,c)}let u=r&&Reflect.apply(r,null,i),f=u?u.payload:s;return d(a(l,e,f),n)}let c=Object.assign(s,{type:e,match:i,toString:()=>e}),l=d(c,n);return l}function y(e,t){return[e,t]}const b=e=>typeof Reflect.get(e??{},`handle`)==`function`,x=(e=[])=>t=>{let n=t.actions;if(b(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,bound:e=>r.has(e)?m(e):void 0};return t.actions=s,s};function S(e,t,n){let{handle:r,prepare:i,scope:a}=C(typeof t==`function`?n:t),o=typeof t==`function`?t:r;return o?v(e,o,a,i):Object.assign(d((...t)=>{let n=i&&Reflect.apply(i,null,t);return d({type:e,payload:n?n.payload:t[0]},a)},a),{type:e,match:t=>t.type===e,toString:()=>e})}const C=e=>{if(!e)return{};let{handle:t,prepare:n,...r}=e,i=typeof t==`function`,a=typeof n==`function`;if(!i&&!a)return{scope:e};let o=Object.keys(r).length>0?r:void 0;return{...i&&{handle:t},...a&&{prepare:n},...o&&{scope:o}}},w=()=>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})},T=e=>typeof e==`string`?S(e):e,E=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},D=(e,t,r,a)=>{let o=e;o[i]=!0;try{E(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},O=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof g)throw e;return Promise.reject(e)}},k=(t,r,i={},o)=>{let l=_(t,r),u=e=>T(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),g=(t,r,i,a)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),D(s,h,e,o))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),E(s,f,r,o))},v=e=>{l===`started`&&(d(),s.signal.aborted?D(s,h,s.signal.reason,o):`error`in e?E(s,m,e.error,o):E(s,p,e.value,o))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),O(()=>(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)=>g(e,n,r,t)},y=Reflect.get(r??{},s)===!0;function b(e,n){return typeof n==`object`?r?g(l,e,n,y):Reflect.apply(l,null,[e,n]):d(a(S,t,e),o)}let x=Object.assign(b,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),S=d(x,o);return S},A=e=>typeof e==`object`&&!!e,j=e=>{if(typeof e==`string`)return e;if(A(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},M=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(j(n),j(t[0]))&&(r===void 0||Object.is(r,t[1]))},N=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`&&M(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)}}}}},P=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 F(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const I=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,L=(e,t,n)=>{n&&e.applyScope?.(t,n)},R=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],z=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},B=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},V=(i=[])=>a=>{let o=a.actions??x()(a),s={handle:(...e)=>{if(!o.handle)throw Error("modulePlugin: the `actions` of the bus is not a registry from `actionsPlugin()`");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=I(a,h),_=(t,n)=>{let r=Reflect.apply(s.handle,null,R(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=B(f),b=z(f,g);try{L(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=N(a),u=a.emit,d=a.get,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:P(c(t.ctx))};try{e&&f.apps.mount(...i)}finally{l.replay()}return f},m=(...e)=>(p(),Reflect.apply(u,a,e));a.emit=m,a.get=((...e)=>(p(),Reflect.apply(d,a,e))),i.length>0&&queueMicrotask(()=>{try{p()}catch(e){n(`the modules of the app could not start`,e)}});let h={get actions(){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:F};return a.app=h,h};export{x as actionsPlugin,S as createAction,k as createJob,F as createModule,w as emitterPlugin,V as modulePlugin,y as setHandler};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,l as t,n,r}from"./context-_HWcdjZf.js";const i=e=>e.type??e,a=(e,t)=>typeof e==`object`?e.payload:t,o=()=>{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()},i=()=>{e={},t={}},a=n=>n===void 0?Object.keys(e).flatMap(a):(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]);return{get:a,add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>r(e,t)},remove:r,clear:i}},s=Symbol(),c=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,s,{value:e,enumerable:!1}),r},l=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&s in e)return e[s]},u=(e,t,n)=>Reflect.apply(e,null,[t,n]),d=(s={})=>{let c=o(),d=(e,t)=>c.add(i(e),t),f=(e,t)=>{let n=d(e,(e,r)=>(n(),t(e,r)));return n},p=(e,t)=>{e===void 0?c.clear():c.remove(i(e),t)},m=e=>n({event:e,bus:g,tracer:s.trace,parent:{ref:r()}}).ctx,h=(e,n)=>{let{onError:r}=s,i=m(n);if(!r){e(n.payload,i);return}let a=e=>{try{r(e,n)}catch(e){t(`onError failed`,e)}};try{let t=e(n.payload,i);typeof t?.then==`function`&&Promise.resolve(t).catch(a)}catch(e){a(e)}},g={get:c.get,on:d,off:p,once:f,emit:(t,n)=>{let r=i(t),o=a(t,n),d={type:r,payload:o},f=l(t);f||=g.actions?.bound?.(r);let p=[...c.get(r),...c.get(`*`)];p.length===0&&!f&&s.onUnhandled?.(d);for(let e of p)h(e,d);if(f){let t=m(d),n=g.actions?.run??u;return e(t,`command`,()=>n(f,o,t))}},use:e=>e(g),ctx:s.context,trace:s.trace};return g};export{c as n,i as r,d as t};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as RaceStarter, c as all, d as GroupOptions, f as Starter, i as take, l as ChildOf, m as delay, n as effectsPlugin, o as race, p as StarterOf, r as TakeOptions, s as allSettled, u as EffectContext } from "./plugin-
|
|
1
|
+
import { B as Task, L as EventMap, N as WithSignal, u as Effect, y as Context } from "./action-creator-DxOvVo8I.js";
|
|
2
|
+
import { a as RaceStarter, c as all, d as GroupOptions, f as Starter, i as take, l as ChildOf, m as delay, n as effectsPlugin, o as race, p as StarterOf, r as TakeOptions, s as allSettled, u as EffectContext } from "./plugin-lJjjd-SN.js";
|
|
3
3
|
//#region src/utils/onAbort.d.ts
|
|
4
4
|
export declare const onAbort: (ctx: {
|
|
5
5
|
signal?: AbortSignal | undefined;
|
package/dist/notrace/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { type Action, type AnyEvent, type Bus, type BusOptions, type
|
|
1
|
+
import { A as Off, B as Task, C as Emittable, D as EventsOf, E as EventPayload, I as createBus, L as EventMap, M as WithContext, N as WithSignal, O as Handler, P as WithType, R as Keys, S as Emit, T as EventLike, V as UnsubscribeCallback, _ as Command, a as WithPayload, b as ContextOf, f as Action, g as BusOptions, h as Bus, j as On, k as HandlerRef, m as AnyEvent, n as Call, p as Actions, v as CommandCall, w as EventKey, x as ContextOption, y as Context, z as PayloadOf } from "./action-creator-DxOvVo8I.js";
|
|
2
|
+
export { type Action, type Actions, type AnyEvent, type Bus, type BusOptions, type Call, type Command, type CommandCall, 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/notrace/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as createBus}from"./bus-
|
|
1
|
+
export{t as createBus}from"./bus-DmKn4SDD.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as EventMap, M as WithContext, R as Keys, b as ContextOf, d as Effects, h as Bus, i as FreeActionCreator, l as BoundForm, t as ActionCreator, y as Context } from "./action-creator-DxOvVo8I.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 {
|
|
1
|
+
import { B as Task, L as EventMap, z as PayloadOf } from "./action-creator-DxOvVo8I.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> = {
|
package/dist/notrace/policies.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./delay-Besb3X1O.js";import{a as r,c as i,i as a,n as o,o as s,t as c}from"./context-_HWcdjZf.js";import{n as l,t as u}from"./
|
|
1
|
+
import{n as e,r as t,t as n}from"./delay-Besb3X1O.js";import{a as r,c as i,i as a,n as o,o as s,t as c}from"./context-_HWcdjZf.js";import{n as l,t as u}from"./lifecycle-key-8iX8RUVD.js";const d=e=>typeof e!=`object`||!e?!1:`then`in e&&typeof e.then==`function`,f=(e,t)=>d(e)?Promise.resolve(e).finally(t):(t(),e),p=e=>Reflect.get(e,u),m=e=>{p(e)?.start()},h=(e,t,n)=>(m(e),r(e,t,n)),g=(e,t)=>{s(e,t,`drop`),p(e)?.drop()},_=(e,t)=>{p(e)?.done(t)},v=(e,t,n)=>{let r=p(e);t?r?.cancel(n):r?.drop()},y=e=>(Reflect.set(e,l,!0),e),b=()=>{},x=(e,t,n)=>typeof e==`function`?n(e,t??{}):t=>n(t,e??{}),S=(e,t)=>{let n=/* @__PURE__ */ new Map;return(r,i)=>{let a=e(r),o=n.get(a);if(!o){let e=t(()=>{n.get(a)===e&&n.delete(a)});o=e,n.set(a,e)}return o(r,i)}},C=(e,t)=>y(e?S(e,t):t(b));function w(e,t){return x(e,t,T)}const T=(e,t)=>C(t.key,t=>E(`latest`,(t,n,r)=>(r(),e(t,n)),t)),E=(e,t,n=b)=>{let r=null;return(o,l)=>{if(r?.abort(),l.signal.aborted)return;let{ctx:u,unlink:f}=a(l);r=u;let p=c(u,e),h=!1,g=()=>{u.signal.aborted||(h=!0,m(u),s(u,e,`start`))};i(u,e=>{v(u,h,e),p(h?`cancel`:`drop`)});let _=()=>{f(),r===u&&(r=null,n())},y=e=>{if(!u.signal.aborted)return p(h?`done`:`drop`),e};try{let e=t(o,u,g);return d(e)?Promise.resolve(e).then(y,e=>{if(!u.signal.aborted)throw p(`error`,e),e}).finally(_):(_(),y(e))}catch(e){if(_(),u.signal.aborted)return;throw p(`error`,e),e}}};function D(e,t,n){return x(t,n,(t,n)=>O(e,t,n))}const O=(e,t,n)=>C(n.key,r=>A(e,t,n,r)),k=(n,r,i,a)=>{let o=a!==b,s=null,c=null;return(l,u)=>{if(u.signal.aborted)return;let d=Date.now(),f=s===null||d-s>=n||d-s<0;return s=d,c!==null&&e(c),c=o?t(a,n):null,i&&f?Promise.resolve(h(u,`debounce`,()=>r(l,u))):(g(u,`debounce`),Promise.resolve(void 0))}},A=(e,t,r,a)=>{let o=r.leading??!1,s=r.trailing??!0;if(!s)return k(e,t,o,a);let c=!1,l=0,u=E(`debounce`,([r,a],o,u)=>{let d=l;return i(o,()=>{l===d&&(c=!1)}),n(o,e).then(()=>{if(c=!1,s&&!a)return u(),t(r,o)})},a);return(e,n)=>{if(n.signal.aborted)return;let r=o&&!c;c=!0,l++;let i=u([e,r],n);return r?Promise.resolve(h(n,`debounce`,()=>t(e,n))):i}};function j(e,t){return x(e,t,M)}const M=(e,t)=>C(t.key,t=>{let n=null;return(r,a)=>{if(a.signal.aborted)return;if(n){g(a,`leading`);return}let o={};n=o;let s=()=>{c(),n===o&&(n=null,t())},c=i(a,s);try{return f(h(a,`leading`,()=>e(r,a)),s)}catch(e){throw s(),e}}});function N(e,t){return x(e,t,P)}const P=(e,t)=>C(t.key,n=>F(e,t,n)),F=(e,t,n)=>{let r=t.concurrency??1,a=t.limit??1/0,o=[],s=0,c=()=>{for(;s<r;){let e=o.shift();if(!e)return;e.start()}};return(l,u)=>new Promise((d,f)=>{if(u.signal.aborted){d(void 0);return}let p=b,m=()=>{p(),g(u,`queue`),d(void 0)},v=()=>{if(p(),u.signal.aborted){m();return}s++;let t=!0,r=()=>{c(),s===0&&o.length===0&&n()},a=(e=!1)=>{t&&(t=!1,s--,e?queueMicrotask(r):r())},g=i(u,()=>{a(!0),d(void 0)}),v;try{v=Promise.resolve(h(u,`queue`,()=>e(l,u)))}catch(e){v=Promise.reject(e)}let y=()=>{g(),a()};v.then(e=>{_(u,{value:e}),y(),d(u.signal.aborted?void 0:e)},e=>{_(u,{error:e}),y(),u.signal.aborted?d(void 0):f(e)})};if(s<r){v();return}if(o.length>=a){if(t.overflow!==`drop-old`||a<=0){m();return}o.shift()?.drop()}let y={start:v,drop:m};o.push(y),p=i(u,()=>{let e=o.indexOf(y);e>=0&&o.splice(e,1),m()})})};function I(e,t,n){return x(t,n,(t,n)=>L(e,t,n))}const L=(e,t,n)=>C(n.key,r=>R(e,t,n,r)),R=(n,r,i,a)=>{let o=i.leading??!0,s=i.trailing??!0,c=a!==b,l=null,u=0,d=null,f=null,p=null,m=!1,_=e=>l===null||e-l>=n||e-l<0||e-u>=n,v=e=>g(e,`throttle`),y=()=>{let e=p;p=null,e&&(v(e.ctx),e.resolve())},x=(e,t)=>(y(),new Promise((n,r)=>{p={payload:e,ctx:t,resolve:n,reject:r}})),S=(e,t,n)=>{y(),u=n,m=!0;try{return h(t,`throttle`,()=>r(e,t))}finally{m=!1}},C=()=>{c&&(f=t(w,n))},w=()=>{if(f=null,!c||d!==null||p)return;let e=Date.now(),r=Math.max(n-(e-(l??-1/0)),n-(e-u));r<=0?a():f=t(w,r)},T=e=>{d=null;let t=p;if(s&&t&&!t.ctx.signal.aborted){p=null;try{t.resolve(S(t.payload,t.ctx,e))}catch(e){t.reject(e)}}else y();w()},E=()=>{let e=Date.now();_(e)?T(e):d=t(E,Math.min(n-(e-(l??e)),n-(e-u)))},D=()=>{f!==null&&(e(f),f=null)},O=(e,t)=>{if(!s)v(t);else return x(e,t)},k=(e,t,n,r)=>{if(!r)v(t);else if(u=n,C(),!o)v(t);else return S(e,t,n)},A=(r,i,a,s)=>s&&d!==null?(e(d),d=t(E,n),S(r,i,a)):d===null&&(d=t(E,n),s&&(u=a,o))?S(r,i,a):O(r,i);return(e,t)=>{if(t.signal.aborted)return;let n=Date.now(),r=!m&&_(n);return l=n,D(),s?A(e,t,n,r):k(e,t,n,r)}},z=Reflect.get(Symbol,`dispose`),B=e=>{let t=new AbortController,n=async(...n)=>{let r=n[0],{ctx:i,unlink:a}=o({event:{type:`withPolicy`,payload:r},parent:{signal:t.signal}});try{return await e(r,i)}finally{a()}},r=e=>{t.abort(e),t=new AbortController},i=Object.assign(n,{cancel:r});return z&&Reflect.set(i,z,()=>r()),i};export{D as debounce,w as latest,j as leading,N as queue,I as throttle,B as withPolicy};
|
package/dist/notrace/redux.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as EventMap, h as Bus } from "./action-creator-DxOvVo8I.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/observable.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as EventMap, U as Keys, r as DataOf, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
//#region src/observable.d.ts
|
|
3
3
|
declare global {
|
|
4
4
|
interface SymbolConstructor {
|
|
@@ -15,7 +15,7 @@ export interface Subscribable<T> {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
export type Observable<T> = Subscribable<T> & {};
|
|
18
|
-
export type Observe<E extends EventMap> = <K extends Keys<E>>(event: K) => Observable<E[K]
|
|
18
|
+
export type Observe<E extends EventMap> = <K extends Keys<E>>(event: K) => Observable<DataOf<E[K]>>;
|
|
19
19
|
export declare const createObserve: <E extends EventMap>(bus: Bus<E>) => Observe<E>;
|
|
20
20
|
/**
|
|
21
21
|
* What a `Subject` reads and writes: the `on` and `emit` of a bus. An instance
|
|
@@ -36,14 +36,14 @@ export type Source<E extends EventMap> = Pick<Bus<E>, "on" | "emit">;
|
|
|
36
36
|
* subscription.unsubscribe();
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare class Subject<E extends EventMap, K extends Keys<E>> implements Observable<E[K]
|
|
40
|
-
[$$observable]: () => Subscribable<E[K]
|
|
39
|
+
export declare class Subject<E extends EventMap, K extends Keys<E>> implements Observable<DataOf<E[K]>> {
|
|
40
|
+
[$$observable]: () => Subscribable<DataOf<E[K]>>;
|
|
41
41
|
readonly source: Source<E>;
|
|
42
42
|
readonly event: K;
|
|
43
43
|
constructor(source: Source<E>, event: K);
|
|
44
|
-
subscribe(observer: Observer<E[K]
|
|
44
|
+
subscribe(observer: Observer<DataOf<E[K]>>): {
|
|
45
45
|
unsubscribe(): void;
|
|
46
46
|
};
|
|
47
|
-
next(payload: E[K]): void;
|
|
47
|
+
next(payload: DataOf<E[K]>): void;
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
package/dist/oop.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as EventMap, W as ListenerOptions, b as Command, t as ActionCreator, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
//#region src/oop/types.d.ts
|
|
3
|
-
type Slots = "ctx" | "
|
|
3
|
+
type Slots = "ctx" | "actions" | "trace" | "addContext" | "applyScope" | "fitScope" | "app" | "use";
|
|
4
4
|
type AnyFunction = (...args: never[]) => unknown;
|
|
5
5
|
/**
|
|
6
6
|
* The methods an instance of a class from `extendBus` gets: the function
|
package/dist/oop.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./bus-
|
|
1
|
+
import{n as e}from"./bus-DlpEluzd.js";const t=/* @__PURE__ */ new WeakMap,n=e=>typeof e==`function`,r=e=>Reflect.ownKeys(e).flatMap(t=>{let r=Reflect.getOwnPropertyDescriptor(e,t)?.value;return n(r)?[{key:t,value:r}]:[]}),i=/* @__PURE__ */ new WeakMap,a=e=>{let n=i.get(e);if(n)return n;let a=/* @__PURE__ */ new Set,o=[];for(let n=e;n&&n!==Object.prototype;n=Reflect.getPrototypeOf(n))for(let{key:e,value:i}of r(n)){if(e===`constructor`||a.has(e))continue;a.add(e);let n=t.get(i);n&&o.push({key:e,method:i,spec:n})}return i.set(e,o),o},o=/* @__PURE__ */ new WeakMap,s=e=>typeof e==`object`&&!!e||typeof e==`function`,c=e=>{let t=o.get(e);if(t)return t;let n=/* @__PURE__ */ new Set;return o.set(e,n),n},l=e=>{if(typeof e==`string`)return e;if(s(e)){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},u=(e,t,n)=>Reflect.apply(Reflect.get(e,t),e,n),d=(e,t,n,r)=>{let[i,a,...o]=r,s=c(e),l={event:i,handler:a,off:()=>{}},d=u(t,n,[i,n===`once`?(e,t)=>(s.delete(l),typeof a==`function`?Reflect.apply(a,null,[e,t]):void 0):a,...o]),f=typeof d==`function`?()=>d():()=>{};return l.off=f,s.add(l),()=>{s.delete(l),f()}},f=(e,t,n)=>{let[r,i]=n,a=c(e);r===void 0&&a.clear();for(let e of[...a])Object.is(l(e.event),l(r))&&(i===void 0||e.handler===i)&&(a.delete(e),e.off());return u(t,`off`,n)},p=e=>{if(!s(e))return;let t=o.get(e);if(t){o.delete(e);for(let e of t)e.off()}},m=/* @__PURE__ */ new Set([`on`,`once`,`off`,`emit`,`ctx`,`actions`,`trace`,`addContext`,`applyScope`,`fitScope`,`app`,`use`]),h=Reflect.get(Symbol,`dispose`),g=e=>typeof e==`function`;var _=class{};const v=(e,t,n,r)=>{n in t||Object.defineProperty(e,n,{configurable:!0,enumerable:!1,...r})},y=/* @__PURE__ */ new WeakMap,b=(e,t)=>{let n=y.get(e);if(n)return n;let r={on:(...n)=>d(e,t,`on`,n),once:(...n)=>d(e,t,`once`,n),off:(...n)=>f(e,t,n)};return y.set(e,r),r},x=(e,t)=>(...n)=>Reflect.apply(Reflect.get(e,t),e,n),S=(e,t)=>{for(let{method:n,spec:r}of a(Reflect.getPrototypeOf(e)??{})){let i=(t,r)=>Reflect.apply(n,e,[t,r]),a=r.wrap?r.wrap(i):i,o=r.once?`once`:`on`;d(e,t,o,[r.event,a,r.options])}},C=(e,t,n)=>{for(let r of[`on`,`once`,`off`])v(e,t,r,{get(){return b(this,n)[r]}});v(e,t,`emit`,{value:x(n,`emit`)});for(let[r,i]of Object.entries(n))typeof i==`function`&&!m.has(r)&&v(e,t,r,{value:x(n,r)});let r=function(){p(this)};v(e,t,`dispose`,{value:r}),h&&v(e,t,h,{value:r}),v(e,t,`bus`,{get:()=>n})},w=(e,t)=>{let n=function(...r){let i=Reflect.construct(t,r,new.target??n);return S(i,e),i};return Object.setPrototypeOf(n,t),n.prototype=Object.create(t.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"name",{value:t.name,configurable:!0}),`bus`in t||Object.defineProperty(n,"bus",{value:e,configurable:!0}),C(n.prototype,t.prototype,e),n};function T(t,n){return g(t)?w(e(),t):w(t,n??_)}function E(e){return t=>e?T(e,t):T(t)}const D=e=>{let[t,n,r]=e;return typeof n==`string`||typeof n==`symbol`?Reflect.get(Object(r),`value`):t},O=(e,n,r,i)=>((...a)=>{let o=D(a);if(typeof o==`function`){let a=typeof n==`function`?n:void 0,s=typeof n==`function`?r:n??r;t.set(o,{event:e,wrap:a,once:i,options:s})}});function k(e,t,n){return O(e,t,n,!1)}function A(e,t,n){return O(e,t,n,!0)}const j=/* @__PURE__ */ new WeakMap,M=t=>{let n=j.get(t);if(n)return n;let r=e();return j.set(t,r),r},N=[`on`,`once`,`off`,`emit`],P=e=>{for(let t of N){let n=Reflect.get(e,t);Reflect.set(e,t,n.bind(e))}};var F=class{constructor(){P(this),S(this,M(this))}get bus(){return M(this)}dispose(){p(this)}};const I={on(...e){return d(this,M(this),`on`,e)},once(...e){return d(this,M(this),`once`,e)},off(...e){return f(this,M(this),e)},emit(...e){let t=M(this);return Reflect.apply(Reflect.get(t,`emit`),t,e)}};for(let e of N)Object.defineProperty(F.prototype,e,{configurable:!0,writable:!0,value:I[e]});h&&Object.defineProperty(F.prototype,h,{configurable:!0,value:function(){this.dispose()}});export{F as Emitter,k as On,A as Once,E as WithBus,p as disposeBus,T as extendBus};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as NoClash } from "./context-types-
|
|
1
|
+
import { F as WithContext, H as EventMap, S as Context, U as Keys, a as FreeActionCreator, d as BoundForm, p as Effects, t as ActionCreator, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
|
+
import { n as NoClash } from "./context-types-hCKgU8sC.js";
|
|
3
3
|
//#region src/utils/delay.d.ts
|
|
4
4
|
type Milliseconds = number | (() => number);
|
|
5
5
|
/**
|
package/dist/policies.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as withPolicy, t as PolicyFunction } from "./with-policy-
|
|
1
|
+
import { H as EventMap, q as Task } from "./action-creator-CcAEvUnw.js";
|
|
2
|
+
import { n as withPolicy, t as PolicyFunction } from "./with-policy-3bhFLEXs.js";
|
|
3
3
|
//#region src/policies/keyed.d.ts
|
|
4
4
|
/** Options shared by every policy that can keep its state per key. */
|
|
5
5
|
type KeyOption<P> = {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as EventKey, H as EventMap, a as FreeActionCreator, q as Task, t as ActionCreator, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
3
|
-
import { t as PolicyFunction } from "./with-policy-
|
|
3
|
+
import { t as PolicyFunction } from "./with-policy-3bhFLEXs.js";
|
|
4
4
|
import { t as StateOf } from "./state-of-C19H6BoV.js";
|
|
5
5
|
//#region src/react/plugin.d.ts
|
|
6
6
|
/** Tells whether two values are the same: `Object.is` unless the caller gives another. */
|
package/dist/redux.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as EventMap, v as Bus } from "./action-creator-CcAEvUnw.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 {
|
|
2
|
-
import { n as ScopeSlots, r as Scoped } from "./types-
|
|
1
|
+
import { H as EventMap, I as WithSignal, c as Scope, f as Effect, m as Signaled, p as Effects, s as EmitScope, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
|
+
import { n as ScopeSlots, r as Scoped } from "./types-FV8fuvI9.js";
|
|
3
3
|
//#region src/scope/effect.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Marks a function whose first parameter is `{ signal }` as an effect, so that
|
package/dist/signal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { H as EventMap, O as EventLike, T as Emit, s as EmitScope, u as WithScope, v as Bus, x as CommandCall } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
//#region src/signal/plugin.d.ts
|
|
3
3
|
/** What the second argument of `emit` takes besides the fields of a scope. */
|
|
4
4
|
type SignalOption = {
|
package/dist/signal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as e}from"./context-UcmrAIhP.js";import{n as t}from"./promise-CSLpzwSR.js";import{t as n}from"./bus-
|
|
1
|
+
import{u as e}from"./context-UcmrAIhP.js";import{n as t}from"./promise-CSLpzwSR.js";import{t as n}from"./bus-DlpEluzd.js";const r=e=>typeof e==`object`&&!!e,i=(e,t)=>{let n=t[0];if(!r(n)||!r(e)&&typeof e!=`function`)return;let i=Reflect.get(n,`signal`);return i instanceof AbortSignal?i:void 0},a=(r,i,a,o)=>{let s=e({signal:r},e=>{for(let{target:t}of i)t.abort(e)});return t(o)?o.then(s,s):n(a)&&s(),o},o=()=>e=>{let t,n,r=e.addContext;e.addContext=e=>{r?.(e),t?.push({target:e}),n?.aborted&&e.abort(n.reason)};let o=e.emit;return e.emit=(e,...r)=>{let s=i(e,r);if(!(s||t))return o(e,...r);let c=t,l=n,u=[];t=s?u:void 0,n=s;let d;try{d=o(e,...r)}finally{t=c,n=l}return s?a(s,u,e,d):d},e};export{o as signalPlugin};
|
package/dist/svelte.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as EventKey, H as EventMap, a as FreeActionCreator, t as ActionCreator, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
import { t as StateOf } from "./state-of-C19H6BoV.js";
|
|
3
3
|
import { Readable } from "svelte/store";
|
|
4
4
|
//#region src/svelte/plugin.d.ts
|
package/dist/trace.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as Tracer, H as EventMap, J as Trace, K as Phase, V as EffectName, X as TraceLogger, Y as TraceEvent, v as Bus } from "./action-creator-CcAEvUnw.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 {
|
|
2
|
-
import { t as BoundOf } from "./plugin-
|
|
1
|
+
import { H as EventMap, c as Scope, l as WithFields, p as Effects } from "./action-creator-CcAEvUnw.js";
|
|
2
|
+
import { t as BoundOf } from "./plugin-CuvIgjnX.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
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as EventKey, H as EventMap, a as FreeActionCreator, t as ActionCreator, v as Bus } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
3
3
|
import { t as StateOf } from "./state-of-C19H6BoV.js";
|
|
4
4
|
import { ShallowRef, WatchSource, WatchStopHandle } from "vue";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as PayloadOf, H as EventMap, q as Task } from "./action-creator-CcAEvUnw.js";
|
|
2
2
|
//#region src/policies/with-policy.d.ts
|
|
3
3
|
/** What `withPolicy` returns: the task as a plain function that can be cancelled. */
|
|
4
4
|
type PolicyFunction<P, R> = {
|