nanoeffects 0.10.0 → 0.11.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/dist/{action-creator-BrZF6hXc.d.ts → action-creator-9e8jesRa.d.ts} +28 -12
- package/dist/actions.d.ts +12 -5
- package/dist/actions.js +1 -1
- package/dist/bus-Cdw5ajKF.js +1 -0
- package/dist/context-CJGW6OWj.js +1 -0
- package/dist/{context-plugin--HkNN1ha.d.ts → context-plugin-Xibukkbj.d.ts} +1 -1
- package/dist/{delay-CIHnOh_L.js → delay-BnBdGPh7.js} +1 -1
- package/dist/dev.d.ts +2 -2
- package/dist/effects.d.ts +2 -2
- package/dist/effects.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/match.d.ts +1 -1
- package/dist/match.js +1 -1
- package/dist/{module-DqKegXHt.d.ts → module-BlkU3i6B.d.ts} +3 -3
- package/dist/notrace/{action-creator-DHAEgwuh.d.ts → action-creator-DQTwMBwP.d.ts} +27 -11
- package/dist/notrace/actions.d.ts +12 -5
- package/dist/notrace/actions.js +1 -1
- package/dist/notrace/bus-G2AdGObY.js +1 -0
- package/dist/notrace/{context-plugin-BapQkGwQ.d.ts → context-plugin-DlZCkcX9.d.ts} +1 -1
- 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/origin-key-BbWN3gmN.js +1 -0
- package/dist/notrace/origin-key-CxK0SkeG.d.ts +10 -0
- package/dist/notrace/{plugin-Cxadz6uU.d.ts → plugin-DOYHG78z.d.ts} +2 -2
- package/dist/notrace/policies.d.ts +1 -1
- package/dist/notrace/redux.d.ts +4 -3
- package/dist/notrace/redux.js +1 -1
- package/dist/observable.d.ts +1 -1
- package/dist/oop.d.ts +13 -7
- package/dist/oop.js +1 -1
- package/dist/origin-key-BbWN3gmN.js +1 -0
- package/dist/origin-key-CxK0SkeG.d.ts +10 -0
- package/dist/{plugin-DkXCvsmB.d.ts → plugin-DHkamZdH.d.ts} +2 -2
- package/dist/policies.d.ts +2 -2
- package/dist/policies.js +1 -1
- package/dist/react.d.ts +15 -8
- package/dist/react.js +1 -1
- package/dist/redux.d.ts +4 -3
- package/dist/redux.js +1 -1
- package/dist/scope.d.ts +2 -2
- package/dist/scope.js +1 -1
- package/dist/signal.d.ts +1 -1
- package/dist/signal.js +1 -1
- package/dist/trace.d.ts +30 -1
- package/dist/trace.js +1 -1
- package/dist/{types-KavbvHix.d.ts → types-ByPzv7tw.d.ts} +2 -2
- package/dist/{with-policy-DBV9dh2F.js → with-policy-CW50Edgk.js} +1 -1
- package/dist/{with-policy-CqUS-VWW.d.ts → with-policy-DpCvSZRk.d.ts} +1 -1
- package/docs/oop.md +2 -0
- package/docs/package.md +1 -1
- package/docs/plugins.md +16 -1
- package/docs/scope.md +1 -1
- package/docs/stores.md +5 -1
- package/docs/tracing.md +121 -1
- package/llms-full.txt +147 -6
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/dist/bus-CkTHUAvq.js +0 -1
- package/dist/context-COgyNlrC.js +0 -1
- package/dist/notrace/bus-BmCTo8BG.js +0 -1
- package/dist/onAbort-BgMfspK4.js +0 -1
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
//#region src/core/types.d.ts
|
|
2
|
+
/** The third argument of `on` and `once`: read by `tracePlugin`, ignored without it. */
|
|
3
|
+
type ListenerOptions = {
|
|
4
|
+
/** Names the listener in the trace: each call of it is a task with this `type`. */
|
|
5
|
+
traceId?: string;
|
|
6
|
+
};
|
|
2
7
|
type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
|
|
3
8
|
type EventMap = Record<string, unknown>;
|
|
4
9
|
type Keys<E> = keyof E & string;
|
|
@@ -7,12 +12,17 @@ type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "ru
|
|
|
7
12
|
type Phase = "start" | "done" | "error" | "cancel" | "drop";
|
|
8
13
|
type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
|
|
9
14
|
id: number;
|
|
10
|
-
|
|
15
|
+
/** Id of the task that started this one, if it has one. */
|
|
16
|
+
parentId?: number;
|
|
11
17
|
type: K;
|
|
12
18
|
effect: EffectName;
|
|
13
19
|
phase: Phase;
|
|
14
20
|
payload: E[K];
|
|
15
21
|
error?: unknown;
|
|
22
|
+
/** The flow the task belongs to: its own, or the nearest ancestor’s; absent without one. */
|
|
23
|
+
traceGroupId?: string;
|
|
24
|
+
/** The id of the root task of the chain; absent on the root itself. */
|
|
25
|
+
rootId?: number;
|
|
16
26
|
}; }[Keys<E>];
|
|
17
27
|
/**
|
|
18
28
|
* The contract of every trace logger: receives each task phase of a bus.
|
|
@@ -35,11 +45,17 @@ declare const anyEventType = "*";
|
|
|
35
45
|
* `task` makes for each task.
|
|
36
46
|
*/
|
|
37
47
|
interface Tracer<Ref extends object = object> {
|
|
38
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Registers a task and returns its handle; `parent` is the handle of its parent task.
|
|
50
|
+
* `traceGroupId` names the flow the task belongs to; a task without one has its parent’s.
|
|
51
|
+
*/
|
|
39
52
|
task(event: {
|
|
40
53
|
type: string;
|
|
41
54
|
payload?: unknown;
|
|
55
|
+
traceGroupId?: string;
|
|
42
56
|
}, parent?: Ref): Ref;
|
|
57
|
+
/** Gives the task another `type`, for a task that is named after it was made (a named listener). A tracer may leave it out. */
|
|
58
|
+
rename?(ref: Ref, type: string): void;
|
|
43
59
|
/** Reports a phase of a task. */
|
|
44
60
|
report(ref: Ref, effect: EffectName, phase: Phase, error?: unknown): void;
|
|
45
61
|
/** Returns `settle(phase, error?)` that reports only the first phase it gets. */
|
|
@@ -117,23 +133,23 @@ type Emit<E extends EventMap> = {
|
|
|
117
133
|
(event: EventLike<E>, scope?: EmitScope<E>): void;
|
|
118
134
|
};
|
|
119
135
|
type On<E extends EventMap> = {
|
|
120
|
-
(event: AnyEvent, fn: Task<EventPayload<E>, E
|
|
121
|
-
<K extends EventKey<E>>(event: K, fn: Task<E[K], E
|
|
136
|
+
(event: AnyEvent, fn: Task<EventPayload<E>, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
137
|
+
<K extends EventKey<E>>(event: K, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
122
138
|
/** An action creator without a payload type: the payload comes from the event map. */
|
|
123
139
|
/** The creators and commands that carry a scope come first: the handler sees their fields. */
|
|
124
|
-
<K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<E[K], WithFields<E, F
|
|
125
|
-
<P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F
|
|
126
|
-
<P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F
|
|
127
|
-
<K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<E[K], E
|
|
140
|
+
<K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<E[K], WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
141
|
+
<P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
142
|
+
<P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
143
|
+
<K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
128
144
|
/** An action creator: the payload comes from it, so an event map is not needed. */
|
|
129
|
-
<P>(creator: ActionCreator<P>, fn: Task<P, E
|
|
145
|
+
<P>(creator: ActionCreator<P>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
130
146
|
/** A command: the payload comes from it too. */
|
|
131
|
-
<P>(command: Command<P, unknown>, fn: Task<P, E
|
|
147
|
+
<P>(command: Command<P, unknown>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
132
148
|
<K extends EventKey<E>, Event extends {
|
|
133
149
|
type: K;
|
|
134
150
|
}>(event: Event & {
|
|
135
151
|
type: K;
|
|
136
|
-
}, fn: Task<E[K], E
|
|
152
|
+
}, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
137
153
|
};
|
|
138
154
|
type Off<E extends EventMap> = {
|
|
139
155
|
/** Removes every listener of every event (including `"*"`). */
|
|
@@ -384,4 +400,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
|
|
|
384
400
|
toString(): T;
|
|
385
401
|
}
|
|
386
402
|
//#endregion
|
|
387
|
-
export { HandlerRef as A, EventMap as B, Emit as C, EventPayload as D, EventLike as E, commandCall as F,
|
|
403
|
+
export { HandlerRef as A, EventMap as B, Emit as C, EventPayload as D, EventLike as E, commandCall as F, Task as G, ListenerOptions as H, createBus as I, TraceLogger as J, Trace as K, Tracer as L, On as M, WithContext as N, EventsOf as O, WithType as P, anyEventType as R, ContextOption as S, EventKey as T, PayloadOf as U, Keys as V, Phase as W, UnsubscribeCallback as Y, Command as _, EmitScope as a, Context as b, WithScope as c, Effects as d, Signaled as f, BusOptions as g, Bus as h, WithPayload as i, Off as j, Handler as k, BoundForm as l, AnyEvent as m, Free as n, Scope as o, Action as p, TraceEvent as q, FreeActionCreator as r, WithFields as s, ActionCreator as t, Effect as u, CommandCall as v, Emittable as w, ContextOf as x, Commands as y, EffectName as z };
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { B as EventMap,
|
|
2
|
-
import { r as Scoped, t as FieldsOfScope } from "./types-
|
|
3
|
-
import { a as createModule, c as CarryingCalls, d as commandsPlugin, f as createCommand, l as MadeCommand, n as ModuleApi, o as modulePlugin, r as ModuleContext, s as Binding, t as Module, u as bindHandler } from "./module-
|
|
1
|
+
import { B as EventMap, G as Task, T as EventKey, U as PayloadOf, c as WithScope, h as Bus, n as Free, o as Scope, r as FreeActionCreator, t as ActionCreator } from "./action-creator-9e8jesRa.js";
|
|
2
|
+
import { r as Scoped, t as FieldsOfScope } from "./types-ByPzv7tw.js";
|
|
3
|
+
import { a as createModule, c as CarryingCalls, d as commandsPlugin, f as createCommand, l as MadeCommand, n as ModuleApi, o as modulePlugin, r as ModuleContext, s as Binding, t as Module, u as bindHandler } from "./module-BlkU3i6B.js";
|
|
4
|
+
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
4
5
|
//#region src/actions/action.d.ts
|
|
5
6
|
type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
|
|
6
7
|
/**
|
|
@@ -52,8 +53,8 @@ type EmitterApi<E extends EventMap> = {
|
|
|
52
53
|
*/
|
|
53
54
|
emitter: {
|
|
54
55
|
/** A creator without a payload type: the payload comes from the event map. */
|
|
55
|
-
<K extends EventKey<E>>(creator: FreeActionCreator<K
|
|
56
|
-
<P, T extends string, A extends unknown[]>(creator: ActionCreator<P, T, A
|
|
56
|
+
<K extends EventKey<E>>(creator: FreeActionCreator<K>, options?: OriginOptions): (...payload: PayloadOf<E[K]>) => void;
|
|
57
|
+
<P, T extends string, A extends unknown[]>(creator: ActionCreator<P, T, A>, options?: OriginOptions): (...args: A) => void;
|
|
57
58
|
};
|
|
58
59
|
};
|
|
59
60
|
/**
|
|
@@ -63,6 +64,9 @@ type EmitterApi<E extends EventMap> = {
|
|
|
63
64
|
* The creator stays a plain `createAction`, so `bus.emit(creator(value))` and
|
|
64
65
|
* `bus.on(creator, …)` work as before. Returns the same bus.
|
|
65
66
|
*
|
|
67
|
+
* With a tracer on the bus, `{ traceId }` names this callback in the trace as the
|
|
68
|
+
* root of the chain it starts, and `{ traceGroupId }` names the flow it belongs to.
|
|
69
|
+
*
|
|
66
70
|
* @example
|
|
67
71
|
* ```ts
|
|
68
72
|
* import { createBus } from "nanoeffects";
|
|
@@ -74,6 +78,9 @@ type EmitterApi<E extends EventMap> = {
|
|
|
74
78
|
*
|
|
75
79
|
* // nanostores: the store calls it with the new value
|
|
76
80
|
* $name.listen(emitNameChanged);
|
|
81
|
+
*
|
|
82
|
+
* // the trace says which store began a chain
|
|
83
|
+
* $cart.listen(bus.emitter(cartChanged, { traceId: "cartStore" }));
|
|
77
84
|
* ```
|
|
78
85
|
*/
|
|
79
86
|
export declare const emitterPlugin: () => <E extends EventMap>(bus: Bus<E>) => Bus<E> & EmitterApi<E>;
|
package/dist/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as e,i as t,l as n,n as r,u as i}from"./context-CJGW6OWj.js";import{t as a}from"./event-0RIBGYqS.js";import{i as o}from"./bus-Cdw5ajKF.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";import{t as u}from"./scope-key-B7l7mUS5.js";const d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=d(a,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(t,r,i,a)=>{let o=t;o[n]=!0;try{S(t,r,i,a)}catch(t){e(`cancel listener`,t)}o[n]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,n,r={},a)=>{let l=g(t,n),u=e=>x(r[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,n,r,o)=>{let s=r,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=i(s,g),S(s,f,n,a))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,a):`error`in e?S(s,m,e.error,a):S(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(o||_(),Reflect.apply(t,null,[n,r]))).then(e=>(v({value:e}),e),t=>{if(l===`idle`)try{_()}catch(t){e(`pending listener`,t)}v({error:t})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,r){return typeof r==`object`?n?_(l,e,r,!1):Reflect.apply(l,null,[e,r]):d(o(T,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,a);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(e=[])=>n=>{let a=n.commands??y()(n),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=e=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(e,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(n,h),_=(e,t)=>{let n=Reflect.apply(o.handle,null,N(g,e,t));return i(f,n),n},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(n,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(n),l=n.emit,u,d=(t=!0)=>{if(u)return u;c.release(),n.emit===f&&(n.emit=l);let i=r({event:{type:`app`,payload:void 0},bus:n,tracer:n.trace});if(u={root:i,apps:s(i.ctx)},t)for(let t of e)u.apps.mount(t);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,n,e));n.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return n.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,n as t,o as n,r}from"./context-CJGW6OWj.js";import{n as i}from"./promise-CSLpzwSR.js";import{n as a,t as o}from"./event-0RIBGYqS.js";const s=`*`,c=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},l=Symbol(),u=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,l,{value:e,enumerable:!1}),r},d=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&l in e)return e[l]},f=(e,t,n)=>Reflect.apply(e,null,[t,n]),p=(s={})=>{let l=c(),u=(e,t)=>l.add(o(e),t),p=(e,t)=>{let n=u(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(o(e),t)},h=(n,a)=>{let{onError:o}=s,{ctx:c}=t({event:a,bus:g,tracer:s.trace,parent:{ref:r()}});if(!o){n(a.payload,c);return}let l=t=>{try{o(t,a)}catch(t){e(`onError failed`,t)}};try{let e=n(a.payload,c);i(e)&&Promise.resolve(e).catch(l)}catch(e){l(e)}},g={on:u,once:p,off:m,emit:(e,i)=>{let c=o(e),u=a(e,i),p={type:c,payload:u},m=d(e),_=[...l.get(c),...l.get(`*`)];_.length===0&&!m&&s.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:e}=t({event:p,bus:g,tracer:s.trace,parent:{ref:r()}}),i=g.commands?.run??f;return n(e,`command`,()=>i(m,u,e))}},use:e=>e(g),ctx:s.context,trace:s.trace};return g};export{s as a,u as i,d as n,p as r,l as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(e,t)=>{globalThis.console?.error(`[nanoeffects] ${e}`,t)},t=()=>{},n=/* @__PURE__ */ new WeakMap,r=t=>{let r=n.get(t);if(r)return r;let i=/* @__PURE__ */ new Set;return n.set(t,i),t.addEventListener(`abort`,()=>{let n=[...i];i.clear();for(let{fn:r}of n)try{r(t.reason)}catch(t){e(`abort callback failed`,t)}},{once:!0}),i},i=(e,n)=>{let{signal:i}=e;if(!i)return t;if(i.aborted)return n(i.reason),t;let a=r(i),o={fn:n};return a.add(o),()=>{a.delete(o)}},a=e=>{let t=new AbortController;return{controller:t,unlink:i({signal:e},e=>t.abort(e))}},o=Symbol(),s=typeof __NANOEFFECTS_TRACE__>`u`||__NANOEFFECTS_TRACE__,c=/* @__PURE__ */ new WeakMap;let l;const u=()=>l,d=()=>{},f=(e,t,n,r)=>{let i=s&&c.get(e);i&&i.tracer.report(i.ref,t,n,r)},p=(e,t)=>{let n=s&&c.get(e);n&&n.tracer.rename?.(n.ref,t)},m=(e,t)=>{let n=s&&c.get(e);return n?n.tracer.settler(n.ref,t):d},h=(e,t,n)=>{let r=s&&c.get(e);return r?r.tracer.run(r.ref,t,e.signal,n):n()},g=(e,t)=>typeof e==`function`?e(t):e,_=({event:e,bus:t,tracer:n,parent:r})=>{let{controller:u,unlink:f}=a(r?.signal),{signal:p}=u,m=s&&n?{tracer:n,ref:n.task(e,r?.ref)}:void 0,v=(...e)=>{if(p.aborted&&!x[o])return;let n=t?.emit,r=l;l=m?.ref;try{return n?.(...e)}finally{l=r}},y=(...e)=>{if(p.aborted)return d;let n=t?.on,r=n?.(...e);if(!r)return d;let a=i({signal:p},r);return()=>{a(),r()}},b=async(r,...i)=>{p.throwIfAborted();let a=i[0],o=_({event:{type:e.type,payload:a},bus:t,tracer:n,parent:{signal:p,ref:m?.ref}});try{return await h(o.ctx,`run`,()=>r(a,o.ctx))}finally{o.unlink()}},x={...g(t?.ctx,e),type:e.type,payload:e.payload,signal:p,abort:e=>u.abort(e),emit:v,on:y,off:t?.off??d,run:b};return t?.addContext?.(x),m&&c.set(x,m),{ctx:x,unlink:f}},v=(e,t)=>{let n=s?c.get(e):void 0;return _({event:{type:t??e.type??``,payload:e.payload},bus:{emit:e.emit,on:e.on,off:e.off,ctx:e},tracer:n?.tracer,parent:{signal:e.signal,ref:n?.ref}})};export{p as a,s as c,e as d,v as i,o as l,_ as n,h as o,u as r,f as s,m as t,i as u};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as EventMap, N as WithContext, h as Bus, x as ContextOf } from "./action-creator-
|
|
1
|
+
import { B as EventMap, N as WithContext, h as Bus, x as ContextOf } from "./action-creator-9e8jesRa.js";
|
|
2
2
|
//#region src/core/context-plugin.d.ts
|
|
3
3
|
/** What a function that makes the fields of a task gets to see. */
|
|
4
4
|
type ContextTask = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{u as e}from"./context-CJGW6OWj.js";const t=2**31-1,n=(e,n)=>{let r={id:null};if(n===1/0)return r;let i=n=>{r.id=setTimeout(()=>{n>t?i(n-t):(r.id=null,e())},Math.min(n,t))};return i(n>0?n:0),r},r=e=>{e.id!==null&&(clearTimeout(e.id),e.id=null)},i=(t,i)=>new Promise((a,o)=>{let s=n(()=>{c(),a()},typeof i==`function`?i():i),c=e(t,e=>{r(s),o(e)})});export{r as n,n as r,i as t};
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as EventMap,
|
|
2
|
-
import { i as WithApp, n as ModuleApi } from "./module-
|
|
1
|
+
import { B as EventMap, Y as UnsubscribeCallback, h as Bus } from "./action-creator-9e8jesRa.js";
|
|
2
|
+
import { i as WithApp, n as ModuleApi } from "./module-BlkU3i6B.js";
|
|
3
3
|
//#region src/dev/types.d.ts
|
|
4
4
|
/** The parts of what `modulePlugin` returned that the diagnostics report. */
|
|
5
5
|
type ReportedApp<E extends EventMap> = Pick<ModuleApi<E>, "mount" | "unmount" | "isMounted">;
|
package/dist/effects.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as EventMap,
|
|
2
|
-
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-
|
|
1
|
+
import { B as EventMap, G as Task, u as Effect } from "./action-creator-9e8jesRa.js";
|
|
2
|
+
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-DHkamZdH.js";
|
|
3
3
|
//#region src/utils/onAbort.d.ts
|
|
4
4
|
export declare const onAbort: (ctx: {
|
|
5
5
|
signal?: AbortSignal | undefined;
|
package/dist/effects.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as e,i as t,o as n,s as r,t as i,u as a}from"./context-CJGW6OWj.js";import{n as o,r as s,t as c}from"./delay-BnBdGPh7.js";const l=(e,t)=>t?.signal?new Promise((n,r)=>{let i=a(t,r);e.then(n,r).finally(i)}):e,u=async(e,n,o,s)=>{n?.signal?.throwIfAborted();let{ctx:c,unlink:u}=t(n??{}),d=i(c,e);r(c,e,`start`),a(c,()=>d(`cancel`));try{let e=await l(o(c),n);return d(`done`),s?.(!1),e}catch(e){throw d(`error`,e),s?.(!0),e}finally{u()}},d=async(e,r)=>{let{ctx:i,unlink:a}=t(e);try{return await n(i,`run`,()=>r(i))}finally{a()}},f=e=>e,p=(e,t)=>n=>e(t,f(n)),m=e=>Array.isArray(e)?Array(e.length):{},h=(e,r)=>{let i=Object.entries(r).map(([r,i])=>{let a=t(e),o={signal:a.ctx.signal,abort:a.ctx.abort},s=()=>i(o);return{key:r,task:new Promise(e=>e(n(a.ctx,`run`,s))).finally(a.unlink),cancel:a.ctx.abort}});return{tasks:i.map(({key:e,task:t})=>[e,t]),cancelAll:()=>{for(let e of i)e.cancel()}}},g=(e,t,n,r,i)=>{let a=()=>{};return u(e,t,async e=>{let t=h(e,n);return a=t.cancelAll,r(t.tasks)},e=>{(e||i===`end`)&&a()})};function _(e,t){return g(`all`,e,t,async e=>{let n=await Promise.all(e.map(([,e])=>e)),r=m(t);for(let[t,[i]]of e.entries())r[i]=n[t];return r},`failure`)}const v=e=>e.then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}));function y(e,t){return g(`allSettled`,e,t,async e=>{let n=await Promise.all(e.map(([,e])=>v(e))),r=m(t);for(let[t,[i]]of e.entries())r[i]=n[t];return r},`failure`)}const b=e=>e>0?e:0,x=(e={})=>{let t=b(e.base??100),n=e.factor??2,r=b(e.max??1/0),i=e.jitter??!1;return e=>{let a=b(Math.min(r,t*n**(e-1)));return i?Math.random()*a||0:a}},S=(t,n)=>t.signal.aborted?Promise.reject(t.signal.reason):new Promise((r,i)=>{let o=[],s=`pending`,c=t=>{try{t()}catch(t){e(`cancel cleanup failed`,t)}},l=a(t,e=>{s=`cancelled`;for(let e of o.reverse())c(e);i(e)}),u=e=>(...t)=>{s===`pending`&&(s=`settled`,l(),o.length=0,e(...t))},d=e=>{s===`pending`?o.push(e):s===`cancelled`&&c(e)};try{n({resolve:u(r),reject:u(i),onCancel:d})}catch(e){u(i)(e)}}),C=e=>t=>{let n=t.addContext,r=Object.entries(e);return t.addContext=e=>{n?.(e);for(let[t,n]of r)t in e||Object.assign(e,{[t]:(...t)=>n(e,...t)})},t},w=(e,t,n,r)=>{if(e.signal.aborted)return Promise.resolve();let i=r.leading??!1,c=r.waitForFn??!1;return u(`poll`,e,e=>new Promise((r,l)=>{let u=0,f=null,p=()=>{f!==null&&(o(f),f=null)},m=e=>{try{f=s(h,typeof n==`function`?n(e):n)}catch(e){p(),l(e)}},h=()=>{f=null,c||m(u+1),g()},g=()=>{let n=u++;d(e,e=>t(e,n)).then(()=>{c&&!e.signal.aborted&&m(u)},e=>{p(),l(e)})};a(e,p),i?(g(),c||m(u)):m(0)})).catch(t=>{if(!e.signal.aborted)throw t})};function T(e,t,n,r={}){if(typeof e!=`object`){let r=t,i=n??{};return(t,n)=>w(n,p(r,t),e,i)}let i=t;return w(e,(e,t)=>i(t),n,r)}function E(e,t){let n=m(t);return Object.keys(t).length===0?Promise.resolve(n):g(`race`,e,t,async e=>{let[t,r]=await Promise.race(e.map(([e,t])=>t.then(t=>[e,t])));return n[t]=r,n},`end`)}const D=(e,t,n)=>typeof e==`function`?e(t,n):e,O=e=>({times:e.times??3,delay:e.delay??0,shouldRetry:e.shouldRetry??(()=>!0)}),k=(e,t,n)=>u(`retry`,e,async e=>{let{times:r,delay:i,shouldRetry:a}=O(n);for(let n=1;;n++)try{return await d(e,e=>t(e,n))}catch(t){if(e.signal.throwIfAborted(),!(n<r)||!a(t,n))throw t;let o=D(i,n,t);o>0&&await c(e,o)}});function A(e,t,n={}){if(typeof e==`function`){let n=e;return(e,r)=>k(r,p(n,e),t??{})}let r=t;return k(e,(e,t)=>r(t),n)}function j(e,t,n={}){return u(`take`,e,r=>new Promise((i,o)=>{let{predicate:s}=n,c=[],l=()=>{for(let e of c)e()},u=e=>{l(),o(e)};c.push(e.on(t,e=>{(!s||s(e))&&(l(),i(e))})),c.push(a(r,u)),c.push(a({signal:n.signal},u))}))}const M=(e,r,i)=>u(`timeout`,e,async e=>{let a=t(e),c=s(()=>a.ctx.abort(new DOMException(`Timed out after ${r}ms`,`TimeoutError`)),r);try{return await l(Promise.resolve(n(a.ctx,`run`,()=>i(a.ctx))),a.ctx)}finally{o(c),a.unlink()}});function N(e,t,n){if(typeof e==`number`){let n=t;return(t,r)=>M(r,e,p(n,t))}let r=t,i=n;return M(e,r,e=>i({signal:e.signal,abort:e.abort}))}export{_ as all,y as allSettled,x as backoff,S as cancellable,c as delay,C as effectsPlugin,a as onAbort,T as poll,E as race,A as retry,j as take,N as timeout};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as HandlerRef, B as EventMap, C as Emit, D as EventPayload, E as EventLike, F as commandCall, G as
|
|
2
|
-
import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin
|
|
1
|
+
import { A as HandlerRef, B as EventMap, C as Emit, D as EventPayload, E as EventLike, F as commandCall, G as Task, I as createBus, J as TraceLogger, K as Trace, L as Tracer, M as On, N as WithContext, O as EventsOf, P as WithType, R as anyEventType, S as ContextOption, T as EventKey, U as PayloadOf, V as Keys, W as Phase, Y as UnsubscribeCallback, _ as Command, b as Context, g as BusOptions, h as Bus, i as WithPayload, j as Off, k as Handler, m as AnyEvent, p as Action, q as TraceEvent, v as CommandCall, w as Emittable, x as ContextOf, y as Commands, z as EffectName } from "./action-creator-9e8jesRa.js";
|
|
2
|
+
import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin-Xibukkbj.js";
|
|
3
3
|
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type ContextTask, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type NoClash, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, contextPlugin, createBus };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,r as t,t as n}from"./bus-
|
|
1
|
+
import{a as e,r as t,t as n}from"./bus-Cdw5ajKF.js";const r=e=>typeof e==`function`,i=e=>({type:Reflect.get(e,`type`),payload:Reflect.get(e,`payload`)}),a=e=>t=>{let n=t.addContext;return t.addContext=t=>{n?.(t);let a=r(e)?e(i(t)):e;for(let[e,n]of Object.entries(a))e in t||Reflect.set(t,e,n)},t};export{e as anyEventType,n as commandCall,a as contextPlugin,t as createBus};
|
package/dist/match.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as EventMap, D as EventPayload,
|
|
1
|
+
import { B as EventMap, D as EventPayload, G as Task, Y as UnsubscribeCallback, h as Bus, p as Action } from "./action-creator-9e8jesRa.js";
|
|
2
2
|
//#region src/match/plugin.d.ts
|
|
3
3
|
/** A function over the action of an event: `{ type, payload }`. */
|
|
4
4
|
type Predicate<E extends EventMap> = (action: Action<E>) => boolean;
|
package/dist/match.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e==`function`&&typeof Reflect.get(e,`type`)!=`string`,t=e=>e,n=()=>n=>{let{on:r,once:i,off:a}=n,o=/* @__PURE__ */ new Map,s=(e,t,i)=>{let a=Reflect.apply(r,n,[`*`,(n,r)=>{if(e({type:Reflect.get(r,`type`),payload:n}))return i&&c(),t(n,r)}]),s={handler:t,remove:c};o.set(e,[...o.get(e)??[],s]);function c(){a();let t=(o.get(e)??[]).filter(e=>e!==s);t.length>0?o.set(e,t):o.delete(e)}return c},c=(t,a,o)=>e(t)?s(t,a,o):Reflect.apply(o?i:r,n,[t,a]);return Object.assign(n,t({on:(e,t)=>c(e,t,!1),once:(e,t)=>c(e,t,!0),off:(t,r)=>{if(r===void 0&&(t===void 0||t===`*`)&&o.clear(),!e(t))return Reflect.apply(a,n,[t,r]);let i=o.get(t)??[],s=i.filter(e=>e.handler===r),c=r===void 0?i:s.slice(0,1);for(let e of c)e.remove()}}))};export{n as matchPlugin};
|
|
1
|
+
const e=e=>typeof e==`function`&&typeof Reflect.get(e,`type`)!=`string`,t=e=>e,n=()=>n=>{let{on:r,once:i,off:a}=n,o=/* @__PURE__ */ new Map,s=(e,t,i)=>{let a=Reflect.apply(r,n,[`*`,(n,r)=>{if(e({type:Reflect.get(r,`type`),payload:n}))return i&&c(),t(n,r)}]),s={handler:t,remove:c};o.set(e,[...o.get(e)??[],s]);function c(){a();let t=(o.get(e)??[]).filter(e=>e!==s);t.length>0?o.set(e,t):o.delete(e)}return c},c=(t,a,o,c)=>e(t)?s(t,a,o):Reflect.apply(o?i:r,n,[t,a,c]);return Object.assign(n,t({on:(e,t,n)=>c(e,t,!1,n),once:(e,t,n)=>c(e,t,!0,n),off:(t,r)=>{if(r===void 0&&(t===void 0||t===`*`)&&o.clear(),!e(t))return Reflect.apply(a,n,[t,r]);let i=o.get(t)??[],s=i.filter(e=>e.handler===r),c=r===void 0?i:s.slice(0,1);for(let e of c)e.remove()}}))};export{n as matchPlugin};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as EventMap,
|
|
2
|
-
import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-
|
|
1
|
+
import { B as EventMap, G as Task, U as PayloadOf, Y as UnsubscribeCallback, _ as Command, b as Context, c as WithScope, h as Bus, o as Scope, v as CommandCall, y as Commands } from "./action-creator-9e8jesRa.js";
|
|
2
|
+
import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-ByPzv7tw.js";
|
|
3
3
|
//#region src/actions/command.d.ts
|
|
4
4
|
/** What `createCommand` returns: a command that also tells whether an action is of its type. */
|
|
5
5
|
type MadeCommand<P, R, T extends string> = Command<P, R> & {
|
|
@@ -53,7 +53,7 @@ type ScopedCommand<P, R, T extends string, F> = ((payload: P) => CommandCall<P,
|
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
declare function createCommand<P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>): MadeCommand<P, R, T>;
|
|
56
|
-
declare function createCommand<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R
|
|
56
|
+
declare function createCommand<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R> | undefined, scope: S): ScopedCommand<P, R, T, FieldsOfScope<EventMap, S>>;
|
|
57
57
|
/** A command (or its type) with the handler to bind to it; `bindHandler` makes one. */
|
|
58
58
|
type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
|
|
59
59
|
/**
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
//#region src/core/types.d.ts
|
|
2
|
+
/** The third argument of `on` and `once`: read by `tracePlugin`, ignored without it. */
|
|
3
|
+
type ListenerOptions = {
|
|
4
|
+
/** Names the listener in the trace: each call of it is a task with this `type`. */
|
|
5
|
+
traceId?: string;
|
|
6
|
+
};
|
|
2
7
|
type PayloadOf<P> = undefined extends P ? [payload?: P] : [payload: P];
|
|
3
8
|
type EventMap = Record<string, unknown>;
|
|
4
9
|
type Keys<E> = keyof E & string;
|
|
@@ -7,12 +12,17 @@ type EffectName = "every" | "latest" | "leading" | "debounce" | "throttle" | "ru
|
|
|
7
12
|
type Phase = "start" | "done" | "error" | "cancel" | "drop";
|
|
8
13
|
type TraceEvent<E = Record<string, unknown>> = { [K in Keys<E>]: {
|
|
9
14
|
id: number;
|
|
10
|
-
|
|
15
|
+
/** Id of the task that started this one, if it has one. */
|
|
16
|
+
parentId?: number;
|
|
11
17
|
type: K;
|
|
12
18
|
effect: EffectName;
|
|
13
19
|
phase: Phase;
|
|
14
20
|
payload: E[K];
|
|
15
21
|
error?: unknown;
|
|
22
|
+
/** The flow the task belongs to: its own, or the nearest ancestor’s; absent without one. */
|
|
23
|
+
traceGroupId?: string;
|
|
24
|
+
/** The id of the root task of the chain; absent on the root itself. */
|
|
25
|
+
rootId?: number;
|
|
16
26
|
}; }[Keys<E>];
|
|
17
27
|
/**
|
|
18
28
|
* The contract of every trace logger: receives each task phase of a bus.
|
|
@@ -35,11 +45,17 @@ declare const anyEventType = "*";
|
|
|
35
45
|
* `task` makes for each task.
|
|
36
46
|
*/
|
|
37
47
|
interface Tracer<Ref extends object = object> {
|
|
38
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Registers a task and returns its handle; `parent` is the handle of its parent task.
|
|
50
|
+
* `traceGroupId` names the flow the task belongs to; a task without one has its parent’s.
|
|
51
|
+
*/
|
|
39
52
|
task(event: {
|
|
40
53
|
type: string;
|
|
41
54
|
payload?: unknown;
|
|
55
|
+
traceGroupId?: string;
|
|
42
56
|
}, parent?: Ref): Ref;
|
|
57
|
+
/** Gives the task another `type`, for a task that is named after it was made (a named listener). A tracer may leave it out. */
|
|
58
|
+
rename?(ref: Ref, type: string): void;
|
|
43
59
|
/** Reports a phase of a task. */
|
|
44
60
|
report(ref: Ref, effect: EffectName, phase: Phase, error?: unknown): void;
|
|
45
61
|
/** Returns `settle(phase, error?)` that reports only the first phase it gets. */
|
|
@@ -117,23 +133,23 @@ type Emit<E extends EventMap> = {
|
|
|
117
133
|
(event: EventLike<E>, scope?: EmitScope<E>): void;
|
|
118
134
|
};
|
|
119
135
|
type On<E extends EventMap> = {
|
|
120
|
-
(event: AnyEvent, fn: Task<EventPayload<E>, E
|
|
121
|
-
<K extends EventKey<E>>(event: K, fn: Task<E[K], E
|
|
136
|
+
(event: AnyEvent, fn: Task<EventPayload<E>, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
137
|
+
<K extends EventKey<E>>(event: K, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
122
138
|
/** An action creator without a payload type: the payload comes from the event map. */
|
|
123
139
|
/** The creators and commands that carry a scope come first: the handler sees their fields. */
|
|
124
|
-
<K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<E[K], WithFields<E, F
|
|
125
|
-
<P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F
|
|
126
|
-
<P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F
|
|
127
|
-
<K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<E[K], E
|
|
140
|
+
<K extends EventKey<E>, F>(creator: FreeActionCreator<K, F> & WithScope<F>, fn: Task<E[K], WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
141
|
+
<P, F>(creator: ActionCreator<P, string, PayloadOf<P>, F> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
142
|
+
<P, F>(command: Command<P, unknown> & WithScope<F>, fn: Task<P, WithFields<E, F>>, options?: ListenerOptions): UnsubscribeCallback;
|
|
143
|
+
<K extends EventKey<E>>(creator: FreeActionCreator<K>, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
128
144
|
/** An action creator: the payload comes from it, so an event map is not needed. */
|
|
129
|
-
<P>(creator: ActionCreator<P>, fn: Task<P, E
|
|
145
|
+
<P>(creator: ActionCreator<P>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
130
146
|
/** A command: the payload comes from it too. */
|
|
131
|
-
<P>(command: Command<P, unknown>, fn: Task<P, E
|
|
147
|
+
<P>(command: Command<P, unknown>, fn: Task<P, E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
132
148
|
<K extends EventKey<E>, Event extends {
|
|
133
149
|
type: K;
|
|
134
150
|
}>(event: Event & {
|
|
135
151
|
type: K;
|
|
136
|
-
}, fn: Task<E[K], E
|
|
152
|
+
}, fn: Task<E[K], E>, options?: ListenerOptions): UnsubscribeCallback;
|
|
137
153
|
};
|
|
138
154
|
type Off<E extends EventMap> = {
|
|
139
155
|
/** Removes every listener of every event (including `"*"`). */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { B as PayloadOf, C as EventKey, H as Task, K as UnsubscribeCallback, R as EventMap, _ as Commands, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context } from "./action-creator-
|
|
2
|
-
import { t as BoundOf } from "./plugin-
|
|
1
|
+
import { B as PayloadOf, C as EventKey, H as Task, K as UnsubscribeCallback, R as EventMap, _ as Commands, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context } from "./action-creator-DQTwMBwP.js";
|
|
2
|
+
import { t as BoundOf } from "./plugin-DOYHG78z.js";
|
|
3
|
+
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
3
4
|
//#region src/scope/types.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* The slots `scopePlugin` fills for `modulePlugin`. They are not on `Bus`: a bus
|
|
@@ -117,7 +118,7 @@ type ScopedCommand<P, R, T extends string, F> = ((payload: P) => CommandCall<P,
|
|
|
117
118
|
* ```
|
|
118
119
|
*/
|
|
119
120
|
export declare function createCommand<P = void, R = void, T extends string = string, E extends EventMap = EventMap>(type: T, handler?: Task<P, E, R>): MadeCommand<P, R, T>;
|
|
120
|
-
export declare function createCommand<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R
|
|
121
|
+
export declare function createCommand<P, R, T extends string, S extends Scope = Record<never, never>>(type: T, handler: Task<P, Scoped<EventMap, S>, R> | undefined, scope: S): ScopedCommand<P, R, T, FieldsOfScope<EventMap, S>>;
|
|
121
122
|
/** A command (or its type) with the handler to bind to it; `bindHandler` makes one. */
|
|
122
123
|
type Binding<E extends EventMap = EventMap> = readonly [Command<never, unknown> | string, Task<never, E, unknown>];
|
|
123
124
|
/**
|
|
@@ -169,8 +170,8 @@ type EmitterApi<E extends EventMap> = {
|
|
|
169
170
|
*/
|
|
170
171
|
emitter: {
|
|
171
172
|
/** A creator without a payload type: the payload comes from the event map. */
|
|
172
|
-
<K extends EventKey<E>>(creator: FreeActionCreator<K
|
|
173
|
-
<P, T extends string, A extends unknown[]>(creator: ActionCreator<P, T, A
|
|
173
|
+
<K extends EventKey<E>>(creator: FreeActionCreator<K>, options?: OriginOptions): (...payload: PayloadOf<E[K]>) => void;
|
|
174
|
+
<P, T extends string, A extends unknown[]>(creator: ActionCreator<P, T, A>, options?: OriginOptions): (...args: A) => void;
|
|
174
175
|
};
|
|
175
176
|
};
|
|
176
177
|
/**
|
|
@@ -180,6 +181,9 @@ type EmitterApi<E extends EventMap> = {
|
|
|
180
181
|
* The creator stays a plain `createAction`, so `bus.emit(creator(value))` and
|
|
181
182
|
* `bus.on(creator, …)` work as before. Returns the same bus.
|
|
182
183
|
*
|
|
184
|
+
* With a tracer on the bus, `{ traceId }` names this callback in the trace as the
|
|
185
|
+
* root of the chain it starts, and `{ traceGroupId }` names the flow it belongs to.
|
|
186
|
+
*
|
|
183
187
|
* @example
|
|
184
188
|
* ```ts
|
|
185
189
|
* import { createBus } from "nanoeffects";
|
|
@@ -191,6 +195,9 @@ type EmitterApi<E extends EventMap> = {
|
|
|
191
195
|
*
|
|
192
196
|
* // nanostores: the store calls it with the new value
|
|
193
197
|
* $name.listen(emitNameChanged);
|
|
198
|
+
*
|
|
199
|
+
* // the trace says which store began a chain
|
|
200
|
+
* $cart.listen(bus.emitter(cartChanged, { traceId: "cartStore" }));
|
|
194
201
|
* ```
|
|
195
202
|
*/
|
|
196
203
|
export declare const emitterPlugin: () => <E extends EventMap>(bus: Bus<E>) => Bus<E> & EmitterApi<E>;
|
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-yYU3_9lq.js";import{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-yYU3_9lq.js";import{a,r as o}from"./bus-G2AdGObY.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";const u=Symbol.for(`nanoeffects.scope`),d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=d(a,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(e,t,r,a)=>{let o=e;o[i]=!0;try{S(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,r,i={},a)=>{let l=g(t,r),u=e=>x(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,r,i,o)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),S(s,f,r,a))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,a):`error`in e?S(s,m,e.error,a):S(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(o||_(),Reflect.apply(t,null,[r,i]))).then(e=>(v({value:e}),e),e=>{if(l===`idle`)try{_()}catch(e){n(`pending listener`,e)}v({error:e})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,n){return typeof n==`object`?r?_(l,e,n,!1):Reflect.apply(l,null,[e,n]):d(o(T,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,a);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function A(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const j=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,M=(e,t,n)=>{n&&e.applyScope?.(t,n)},N=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],P=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},F=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},I=(n=[])=>i=>{let a=i.commands??y()(i),o={handle:(...e)=>{if(!a.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(a.handle,null,e)}},s=n=>{let r=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;return{mount:c=>{let l=r.get(c);if(l)return l;let u=a.get(c.name);u&&r.get(u)?.();let d=t(n,c.name),f=d.ctx,p=s(f),m=()=>{r.delete(c),a.get(c.name)===c&&a.delete(c.name),f.abort(),d.unlink()};r.set(c,m),a.set(c.name,c);let h=c.scope,g=j(i,h),_=(t,n)=>{let r=Reflect.apply(o.handle,null,N(g,t,n));return e(f,r),r},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=F(f),b=P(f,g);try{M(i,f,h),c.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},c=k(i),l=i.emit,u,d=(e=!0)=>{if(u)return u;c.release(),i.emit===f&&(i.emit=l);let t=r({event:{type:`app`,payload:void 0},bus:i,tracer:i.trace});if(u={root:t,apps:s(t.ctx)},e)for(let e of n)u.apps.mount(e);return c.replay(),u},f=(...e)=>(d(),Reflect.apply(l,i,e));i.emit=f;let p={get commands(){return d(),a},mount:e=>{let{root:t,apps:n}=d();return t.ctx.signal.throwIfAborted(),n.mount(e)},unmount:e=>d().apps.unmount(e),isMounted:e=>d().apps.isMounted(e),dispose:()=>d(!1).root.ctx.abort(),createModule:A};return i.app=p,p};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,A as createModule,b as emitterPlugin,I as modulePlugin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,l as t,n,r}from"./context-yYU3_9lq.js";import{n as i}from"./promise-CSLpzwSR.js";const a=e=>typeof e==`string`?e:e.type,o=(e,t)=>typeof e==`object`?e.payload:t,s=`*`,c=()=>{let e={},t={},n=n=>(t[n]=void 0,e[n]??=/* @__PURE__ */ new Map,e[n]),r=(e,t)=>{let r=n(e),i=r.get(t)??0;i>1?r.set(t,i-1):t?r.delete(t):r.clear()};return{get:n=>(t[n]??=[...e[n]??[]].flatMap(([e,t])=>Array(t).fill(e)),t[n]),add:(e,t)=>{let i=n(e);return i.set(t,(i.get(t)??0)+1),()=>{r(e,t)}},remove:r,clear:()=>{e={},t={}}}},l=Symbol(),u=(e,t,n)=>{let r={type:t,payload:n};return Object.defineProperty(r,l,{value:e,enumerable:!1}),r},d=e=>{if(typeof e==`function`)return e;if(typeof e==`object`&&e&&l in e)return e[l]},f=(e,t,n)=>Reflect.apply(e,null,[t,n]),p=(s={})=>{let l=c(),u=(e,t)=>l.add(a(e),t),p=(e,t)=>{let n=u(e,(e,r)=>(n(),t(e,r)));return n},m=(e,t)=>{e===void 0?l.clear():l.remove(a(e),t)},h=(e,a)=>{let{onError:o}=s,{ctx:c}=n({event:a,bus:g,tracer:s.trace,parent:{ref:r()}});if(!o){e(a.payload,c);return}let l=e=>{try{o(e,a)}catch(e){t(`onError failed`,e)}};try{let t=e(a.payload,c);i(t)&&Promise.resolve(t).catch(l)}catch(e){l(e)}},g={on:u,once:p,off:m,emit:(t,i)=>{let c=a(t),u=o(t,i),p={type:c,payload:u},m=d(t),_=[...l.get(c),...l.get(`*`)];_.length===0&&!m&&s.onUnhandled?.(p);for(let e of _)h(e,p);if(m){let{ctx:t}=n({event:p,bus:g,tracer:s.trace,parent:{ref:r()}}),i=g.commands?.run??f;return e(t,`command`,()=>i(m,u,t))}},use:e=>e(g),ctx:s.context,trace:s.trace};return g};export{a,s as i,p as n,u as r,l as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as EventMap, j as WithContext, p as Bus, y as ContextOf } from "./action-creator-
|
|
1
|
+
import { R as EventMap, j as WithContext, p as Bus, y as ContextOf } from "./action-creator-DQTwMBwP.js";
|
|
2
2
|
//#region src/core/context-plugin.d.ts
|
|
3
3
|
/** What a function that makes the fields of a task gets to see. */
|
|
4
4
|
type ContextTask = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as Task, R as EventMap, l as Effect } from "./action-creator-
|
|
2
|
-
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-
|
|
1
|
+
import { H as Task, R as EventMap, l as Effect } from "./action-creator-DQTwMBwP.js";
|
|
2
|
+
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-DOYHG78z.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,3 +1,3 @@
|
|
|
1
|
-
import { A as On, B as PayloadOf, C as EventKey, D as Handler, E as EventsOf, F as Tracer, G as TraceLogger, H as Task, I as anyEventType, K as UnsubscribeCallback, L as EffectName, M as WithType, N as commandCall, O as HandlerRef, P as createBus, R as EventMap, S as Emittable, T as EventPayload, U as Trace, V as Phase, W as TraceEvent, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf, z as Keys } from "./action-creator-
|
|
2
|
-
import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin-
|
|
1
|
+
import { A as On, B as PayloadOf, C as EventKey, D as Handler, E as EventsOf, F as Tracer, G as TraceLogger, H as Task, I as anyEventType, K as UnsubscribeCallback, L as EffectName, M as WithType, N as commandCall, O as HandlerRef, P as createBus, R as EventMap, S as Emittable, T as EventPayload, U as Trace, V as Phase, W as TraceEvent, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf, z as Keys } from "./action-creator-DQTwMBwP.js";
|
|
2
|
+
import { n as NoClash, r as contextPlugin, t as ContextTask } from "./context-plugin-DlZCkcX9.js";
|
|
3
3
|
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type ContextTask, type EffectName, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type NoClash, type Off, type On, type PayloadOf, type Phase, type Task, type Trace, type TraceEvent, type TraceLogger, type Tracer, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, anyEventType, commandCall, contextPlugin, createBus };
|
package/dist/notrace/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,n as t,t as n}from"./bus-
|
|
1
|
+
import{i as e,n as t,t as n}from"./bus-G2AdGObY.js";const r=e=>typeof e==`function`,i=e=>({type:Reflect.get(e,`type`),payload:Reflect.get(e,`payload`)}),a=e=>t=>{let n=t.addContext;return t.addContext=t=>{n?.(t);let a=r(e)?e(i(t)):e;for(let[e,n]of Object.entries(a))e in t||Reflect.set(t,e,n)},t};export{e as anyEventType,n as commandCall,a as contextPlugin,t as createBus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=Symbol.for(`nanoeffects.origin`);export{e as t};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/core/origin-key.d.ts
|
|
2
|
+
/** What an emitter tells the trace about itself. */
|
|
3
|
+
type OriginOptions = {
|
|
4
|
+
/** Names the subscription that emits; it is the `type` of the root task of the trace. */
|
|
5
|
+
traceId?: string;
|
|
6
|
+
/** Names the flow the emit belongs to; every task below it has it too. */
|
|
7
|
+
traceGroupId?: string;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { OriginOptions as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as EventMap, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, z as Keys } from "./action-creator-
|
|
2
|
-
import { n as NoClash } from "./context-plugin-
|
|
1
|
+
import { R as EventMap, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, z as Keys } from "./action-creator-DQTwMBwP.js";
|
|
2
|
+
import { n as NoClash } from "./context-plugin-DlZCkcX9.js";
|
|
3
3
|
//#region src/utils/delay.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Resolves after `ms`, or rejects early if `ctx.signal` aborts. `ms` can be a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as PayloadOf, H as Task, R as EventMap } from "./action-creator-
|
|
1
|
+
import { B as PayloadOf, H as Task, R as EventMap } from "./action-creator-DQTwMBwP.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/redux.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { R as EventMap, p as Bus } from "./action-creator-
|
|
1
|
+
import { R as EventMap, p as Bus } from "./action-creator-DQTwMBwP.js";
|
|
2
|
+
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
2
3
|
//#region src/store/redux/middleware.d.ts
|
|
3
4
|
/** What Redux passes through a middleware: an action is a plain object with a `type`. */
|
|
4
5
|
type ReduxAction = {
|
|
5
6
|
type: string;
|
|
6
7
|
payload?: unknown;
|
|
7
8
|
};
|
|
8
|
-
type NanoeffectsMiddlewareOptions = {
|
|
9
|
+
type NanoeffectsMiddlewareOptions = OriginOptions & {
|
|
9
10
|
/** Return `false` for the actions that the bus should not get. Default: all of them. */
|
|
10
11
|
filter?: (action: ReduxAction) => boolean;
|
|
11
12
|
/** Receives an error that `emit` throws, so `dispatch` does not. Default: the error is thrown. */
|
|
@@ -21,7 +22,7 @@ type ReduxStoreApi<State = unknown> = {
|
|
|
21
22
|
}) => unknown;
|
|
22
23
|
getState: () => State;
|
|
23
24
|
};
|
|
24
|
-
type EffectsMiddlewareOptions = Pick<NanoeffectsMiddlewareOptions, "filter">;
|
|
25
|
+
type EffectsMiddlewareOptions = Pick<NanoeffectsMiddlewareOptions, "filter" | "traceId" | "traceGroupId">;
|
|
25
26
|
/**
|
|
26
27
|
* Makes the Redux middleware that feeds a bus you already have: the actions of
|
|
27
28
|
* the store reach its handlers, and every task gets `ctx.store`, the `dispatch`
|
package/dist/notrace/redux.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
import{t as e}from"./origin-key-BbWN3gmN.js";const t=e=>typeof e==`object`&&!!e&&`type`in e,n=(n,r={})=>{let i=n.emit,a=t=>{try{let a=Reflect.get(n,e);a?a(t,r):i(t)}catch(e){if(!r.onError)throw e;r.onError(e,t)}};return()=>e=>n=>{let i=e(n);return t(n)&&(r.filter?.(n)??!0)&&a(n),i}},r=(e,t={})=>{let r,i=/* @__PURE__ */ new WeakMap,a=e.addContext;e.addContext=e=>{a?.(e);let t=r;if(!t)return;let{type:n}=e;Object.assign(e,{store:{getState:t.getState,dispatch:e=>{typeof e==`object`&&e&&i.set(e,n);let r=e;return t.dispatch(r)}}})};let o=n(e,{...t.traceId===void 0?{}:{traceId:t.traceId},...t.traceGroupId===void 0?{}:{traceGroupId:t.traceGroupId},filter:e=>i.get(e)!==e.type&&(t.filter?.(e)??!0),onError:(e,{type:t})=>{globalThis.console?.error(`[nanoeffects] handler of "${t}" failed`,e)}});return e=>(r=e,o())};export{r as createEffectsMiddleware};
|
package/dist/observable.d.ts
CHANGED