nanoeffects 0.19.1 → 0.21.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-HFA_LZOH.d.ts → action-creator-Bpa8BUS9.d.ts} +18 -7
- package/dist/actions.d.ts +3 -3
- package/dist/actions.js +1 -1
- package/dist/{context-types-BNcs43eY.d.ts → context-types-BKIH5a8s.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 +4 -8
- package/dist/index.d.ts +2 -2
- package/dist/match.d.ts +1 -1
- package/dist/{module-DTf73Wdq.d.ts → module-B0KVDNjY.d.ts} +14 -9
- package/dist/mount-each-D54UqAhZ.js +1 -0
- package/dist/notrace/{action-creator-CbFf398i.d.ts → action-creator-D2CotugT.d.ts} +16 -7
- package/dist/notrace/actions.d.ts +14 -9
- package/dist/notrace/actions.js +1 -1
- package/dist/notrace/effects.d.ts +4 -8
- package/dist/notrace/index.d.ts +2 -2
- package/dist/notrace/{plugin-C5vIjxhR.d.ts → plugin-C6KA4dX-.d.ts} +1 -1
- package/dist/notrace/policies.d.ts +51 -6
- package/dist/notrace/policies.js +1 -1
- package/dist/notrace/redux.d.ts +1 -1
- package/dist/observable.d.ts +1 -1
- package/dist/oop.d.ts +1 -1
- package/dist/{plugin-Sy8z9IId.d.ts → plugin-D9UTzGRG.d.ts} +2 -2
- package/dist/policies.d.ts +52 -7
- package/dist/policies.js +1 -1
- package/dist/react.d.ts +9 -8
- package/dist/redux.d.ts +1 -1
- package/dist/scope.d.ts +4 -4
- package/dist/signal.d.ts +1 -1
- package/dist/state-of-C19H6BoV.d.ts +10 -0
- package/dist/trace.d.ts +1 -1
- package/dist/{types-DaZT158m.d.ts → types-CbdJKC2z.d.ts} +2 -2
- package/dist/vue.d.ts +72 -0
- package/dist/vue.js +1 -0
- package/dist/{with-policy-C_mX7S54.d.ts → with-policy-BeH8wCkX.d.ts} +1 -1
- package/docs/README.md +2 -0
- package/docs/actions.md +31 -1
- package/docs/chat-example.md +246 -0
- package/docs/migrating-from-rxjs.md +58 -1
- package/docs/package.md +1 -0
- package/docs/plugins.md +3 -3
- package/docs/policies.md +27 -0
- package/docs/query-libraries.md +2 -0
- package/docs/react.md +5 -3
- package/docs/starter.md +25 -1
- package/docs/typescript.md +14 -0
- package/docs/vue.md +96 -0
- package/llms-full.txt +517 -10
- package/llms.txt +4 -2
- package/package.json +25 -4
|
@@ -75,6 +75,19 @@ type EventPayload<E extends EventMap> = E[EventKey<E>];
|
|
|
75
75
|
type WithType<K extends string> = {
|
|
76
76
|
type: K;
|
|
77
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* An object that has the `signal` of a task: the context of a task, `{ signal }`, or the
|
|
80
|
+
* `{ signal, abort }` that a starter of `all` and `race` gets. A function that only needs to
|
|
81
|
+
* stop its request when the task is aborted takes `WithSignal`:
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const search = (query: string, { signal }: WithSignal) => fetch(`/search?q=${query}`, { signal });
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
type WithSignal = {
|
|
89
|
+
signal: AbortSignal;
|
|
90
|
+
};
|
|
78
91
|
type HandlerRef<E extends EventMap, Response = unknown> = (action: Action<E>) => Response;
|
|
79
92
|
type Handler<E extends EventMap, Response = unknown, K extends EventKey<E> = EventKey<E>> = { [P in K]: {
|
|
80
93
|
type: P;
|
|
@@ -278,12 +291,10 @@ type BusOptions<E extends EventMap> = {
|
|
|
278
291
|
declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
|
|
279
292
|
//#endregion
|
|
280
293
|
//#region src/core/effect-types.d.ts
|
|
281
|
-
/** What an effect needs of the task it runs for: its signal.
|
|
282
|
-
type Signaled =
|
|
283
|
-
signal: AbortSignal;
|
|
284
|
-
};
|
|
294
|
+
/** What an effect needs of the task it runs for: its signal. The name `WithSignal` is the one to use; this one stays for `nanoeffects/scope`. */
|
|
295
|
+
type Signaled = WithSignal;
|
|
285
296
|
/** An effect: a function whose first parameter takes `{ signal }`, like `retry(ctx, fn)`. */
|
|
286
|
-
type SignalFirst = (ctx:
|
|
297
|
+
type SignalFirst = (ctx: WithSignal, ...args: never[]) => unknown;
|
|
287
298
|
/** The effects of a scope or of `effectsPlugin`, by the name they get on the context. */
|
|
288
299
|
type Effects = Record<string, SignalFirst>;
|
|
289
300
|
declare const bound: unique symbol;
|
|
@@ -299,7 +310,7 @@ declare const bound: unique symbol;
|
|
|
299
310
|
* const first: Effect<First> = (ctx, items) => items[0];
|
|
300
311
|
* ```
|
|
301
312
|
*/
|
|
302
|
-
type Effect<F extends (...args: never[]) => unknown> = ((ctx:
|
|
313
|
+
type Effect<F extends (...args: never[]) => unknown> = ((ctx: WithSignal, ...args: Parameters<F>) => ReturnType<F>) & {
|
|
303
314
|
readonly [bound]?: F;
|
|
304
315
|
};
|
|
305
316
|
/** The bound form of a plain effect: the first parameter is gone, and so are its generics. */
|
|
@@ -400,4 +411,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
|
|
|
400
411
|
toString(): T;
|
|
401
412
|
}
|
|
402
413
|
//#endregion
|
|
403
|
-
export { HandlerRef as A,
|
|
414
|
+
export { HandlerRef as A, Keys as B, Emit as C, EventPayload as D, EventLike as E, WithType as F, Trace as G, PayloadOf as H, createBus as I, UnsubscribeCallback as J, TraceEvent as K, Tracer as L, On as M, WithContext as N, EventsOf as O, WithSignal as P, EffectName as R, ContextOption as S, EventKey as T, Phase as U, ListenerOptions as V, Task as W, Command as _, EmitScope as a, Context as b, WithScope as c, Effects as d, Signaled as f, BusOptions as g, Bus as h, WithPayload as i, Off as j, Handler as k, BoundForm as l, AnyEvent as m, Free as n, Scope as o, Action as p, TraceLogger as q, FreeActionCreator as r, WithFields as s, ActionCreator as t, Effect as u, CommandCall as v, Emittable as w, ContextOf as x, Commands as y, EventMap as z };
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 { H as PayloadOf, T as EventKey, W as Task, c as WithScope, h as Bus, n as Free, o as Scope, r as FreeActionCreator, t as ActionCreator, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
import { r as Scoped, t as FieldsOfScope } from "./types-CbdJKC2z.js";
|
|
3
|
+
import { a as createModule, c as CarryingCalls, d as commandsPlugin, f as createCommand, l as MadeCommand, n as ModuleApi, o as modulePlugin, r as ModuleContext, s as Binding, t as Module, u as bindHandler } from "./module-B0KVDNjY.js";
|
|
4
4
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
5
5
|
//#region src/actions/action.d.ts
|
|
6
6
|
type ScopedCreator<P, T extends string, F> = [P] extends [Free] ? FreeActionCreator<T, F> & WithScope<F> : ActionCreator<P, T, PayloadOf<P>, F> & WithScope<F>;
|
package/dist/actions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,i as t,l as n,n as r,u as i}from"./context-CJGW6OWj.js";import{t as a}from"./event-0RIBGYqS.js";import{r as o}from"./bus-duCCrqrr.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";import{t as u}from"./scope-key-B7l7mUS5.js";const
|
|
1
|
+
import{d as e,i as t,l as n,n as r,u as i}from"./context-CJGW6OWj.js";import{t as a}from"./event-0RIBGYqS.js";import{r as o}from"./bus-duCCrqrr.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";import{t as u}from"./scope-key-B7l7mUS5.js";import{t as d}from"./mount-each-D54UqAhZ.js";const f=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),p=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),m=e=>Reflect.get(e,u);function h(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(f((...t)=>f({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var g=class extends Error{};function _(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new g(`No handler for command "${e}"`);return t(r,i)}return f(o(s,e,r),n)}let a=Object.assign(i,{type:e,match:r}),s=f(a,n);return s}const v=(e,t)=>[e,t],y=e=>typeof Reflect.get(e??{},`handle`)==`function`,b=(e=[])=>t=>{let n=t.commands;if(y(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function o(e,t){if(t)return i(a(e),t);let n=e.map(([e,t])=>i(a(e),t));return()=>{for(let e of n)e()}}o(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:o};return t.commands=s,s},x=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},S=e=>typeof e==`string`?h(e):e,C=(e,t,n,r)=>{let i=m(t);e.emit(Reflect.apply(t,null,[n]),r&&i?p(r,i):r)},w=(t,r,i,a)=>{let o=t;o[n]=!0;try{C(t,r,i,a)}catch(t){e(`cancel listener`,t)}o[n]=!1},T=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof g)throw e;return Promise.reject(e)}},E=(t,n,r={},a)=>{let l=_(t,n),u=e=>S(r[e]??`${t}/${e}`),d=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),g=(t,n,r,o)=>{let s=r,l=`idle`,u=()=>{},f=()=>{l=`closed`,u()},g=e=>{l===`started`&&(f(),w(s,h,e,a))},_=()=>{l===`idle`&&(l=`started`,u=i(s,g),C(s,d,n,a))},v=e=>{l===`started`&&(f(),s.signal.aborted?w(s,h,s.signal.reason,a):`error`in e?C(s,m,e.error,a):C(s,p,e.value,a))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),T(()=>(o||_(),Reflect.apply(t,null,[n,r]))).then(e=>(v({value:e}),e),t=>{if(l===`idle`)try{_()}catch(t){e(`pending listener`,t)}v({error:t})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>g(e,n,r,t)};function y(e,r){return typeof r==`object`?n?g(l,e,r,!1):Reflect.apply(l,null,[e,r]):f(o(x,t,e),a)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:d,success:p,fail:m,cancel:h}),x=f(b,a);return x},D=e=>typeof e==`object`&&!!e,O=e=>{if(typeof e==`string`)return e;if(D(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},k=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(O(n),O(t[0]))&&(r===void 0||Object.is(r,t[1]))},A=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&k(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function j(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const M=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,N=(e,t,n)=>{n&&e.applyScope?.(t,n)},P=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],F=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},I=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},L=(n=[])=>a=>{let o=a.commands??b()(a),s={handle:(...e)=>{if(!o.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(o.handle,null,e)}},c=e=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map;return{mount:o=>{let l=n.get(o);if(l)return l;let u=r.get(o.name);u&&n.get(u)?.();let d=t(e,o.name),f=d.ctx,p=c(f),m=()=>{n.delete(o),r.get(o.name)===o&&r.delete(o.name),f.abort(),d.unlink()};n.set(o,m),r.set(o.name,o);let h=o.scope,g=M(a,h),_=(e,t)=>{let n=Reflect.apply(s.handle,null,P(g,e,t));return i(f,n),n},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=I(f),b=F(f,g);try{N(a,f,h),o.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>n.get(e)?.(),isMounted:e=>n.has(e)}},l=A(a),u=a.emit,f,p=(e=!0)=>{if(f)return f;l.release(),a.emit===m&&(a.emit=u);let t=r({event:{type:`app`,payload:void 0},bus:a,tracer:a.trace});f={root:t,apps:d(c(t.ctx))};try{e&&f.apps.mount(...n)}finally{l.replay()}return f},m=(...e)=>(p(),Reflect.apply(u,a,e));a.emit=m,n.length>0&&queueMicrotask(()=>{try{p()}catch(t){e(`the modules of the app could not start`,t)}});let h={get commands(){return p(),o},mount:(...e)=>{let{root:t,apps:n}=p();return t.ctx.signal.throwIfAborted(),n.mount(...e)},unmount:(...e)=>p().apps.unmount(...e),isMounted:e=>p().apps.isMounted(e),dispose:()=>p(!1).root.ctx.abort(),createModule:j};return a.app=h,h};export{v as bindHandler,b as commandsPlugin,h as createAction,_ as createCommand,E as createJob,j as createModule,x as emitterPlugin,L as modulePlugin};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { x as ContextOf, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
2
|
//#region src/core/context-types.d.ts
|
|
3
3
|
/** What a function that makes the fields of a task gets to see. */
|
|
4
4
|
type ContextTask = {
|
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as WithContext,
|
|
2
|
-
import { n as NoClash, t as ContextTask } from "./context-types-
|
|
1
|
+
import { N as WithContext, h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
import { n as NoClash, t as ContextTask } from "./context-types-BKIH5a8s.js";
|
|
3
3
|
//#region src/context/plugin.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Puts `fields` on the context of every task of the bus: a store, a client, a
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as WithApp, n as ModuleApi } from "./module-
|
|
1
|
+
import { J as UnsubscribeCallback, h as Bus, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
import { i as WithApp, n as ModuleApi } from "./module-B0KVDNjY.js";
|
|
3
3
|
//#region src/dev/types.d.ts
|
|
4
4
|
/** The parts of what `modulePlugin` returned that the diagnostics report. */
|
|
5
5
|
type ReportedApp<E extends EventMap> = Pick<ModuleApi<E>, "mount" | "unmount" | "isMounted">;
|
package/dist/dev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./event-0RIBGYqS.js";const
|
|
1
|
+
import{t as e}from"./event-0RIBGYqS.js";import{t}from"./mount-each-D54UqAhZ.js";const n=`[nanoeffects]`,r=(e={})=>t=>{let{maxListeners:n=10,leaks:r=!0,modules:i=!0,app:s}=e,c=e.log??(e=>console.warn(e)),l=e.log??(e=>console.info(e)),u=[];return r&&u.push(a(t,n,c)),i&&u.push(o(t,s,l)),()=>{for(let e of u.splice(0))e()}},i=t=>typeof t==`function`&&typeof Reflect.get(t,`type`)!=`string`?`*`:e(t),a=(e,t,r)=>{let a=e.on,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=!0,l=(...l)=>{if(!c)return Reflect.apply(a,e,l);let[u]=l,d=i(u),f=(o.get(d)??0)+1;o.set(d,f),f>t&&!s.has(d)&&(s.add(d),r(`${n} ${f} listeners of "${d}" were added and not unsubscribed (more than ${t}). A file that is reloaded and subscribes again, or an unsubscribe that is never called?`));let p=Reflect.apply(a,e,l),m=!1;return()=>{if(!m){m=!0;let e=(o.get(d)??1)-1;o.set(d,e),e<=t&&s.delete(d)}p()}};return e.on=l,()=>{c=!1,e.on===l&&(e.on=a)}},o=(e,t,n)=>{let r=t??e.app;if(r)return s(r,n);let i,a;return Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,get:()=>i,set:e=>{a?.(),i=e,a=e?s(e,n):void 0}}),()=>{a?.(),Object.defineProperty(e,"app",{configurable:!0,enumerable:!0,writable:!0,value:i})}},s=(e,r)=>{let{mount:i,unmount:a}=e,o=/* @__PURE__ */ new Map,s=t({mount:t=>{let a=o.get(t.name);if(a===t&&e.isMounted(t))return i(t);let s=a!==void 0&&e.isMounted(a),c=i(t);return o.set(t.name,t),r(`${n} module "${t.name}" ${s?`replaced`:`mounted`}`),()=>{e.isMounted(t)&&r(`${n} module "${t.name}" unmounted`),c()}},unmount:t=>{e.isMounted(t)&&r(`${n} module "${t.name}" unmounted`),a(t)},isMounted:t=>e.isMounted(t)});return e.mount=s.mount,e.unmount=s.unmount,()=>{e.mount=i,e.unmount=a}};export{r as devPlugin};
|
package/dist/effects.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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 { P as WithSignal, W as Task, u as Effect, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-D9UTzGRG.js";
|
|
3
3
|
//#region src/utils/onAbort.d.ts
|
|
4
4
|
export declare const onAbort: (ctx: {
|
|
5
5
|
signal?: AbortSignal | undefined;
|
|
@@ -66,9 +66,7 @@ type CancellableExecutor<T> = (handle: CancellableHandle<T>) => void;
|
|
|
66
66
|
* );
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export declare const cancellable: <T = void>(ctx:
|
|
70
|
-
signal: AbortSignal;
|
|
71
|
-
}, executor: CancellableExecutor<T>) => Promise<T>;
|
|
69
|
+
export declare const cancellable: <T = void>(ctx: WithSignal, executor: CancellableExecutor<T>) => Promise<T>;
|
|
72
70
|
//#endregion
|
|
73
71
|
//#region src/effects/poll.d.ts
|
|
74
72
|
type PollOptions = {
|
|
@@ -108,9 +106,7 @@ type PollOptions = {
|
|
|
108
106
|
*/
|
|
109
107
|
type PollMs = number | ((call: number) => number);
|
|
110
108
|
export declare function poll<P, E extends EventMap, R>(ms: PollMs, task: Task<P, E, R>, options?: PollOptions): Task<P, E, Promise<void>>;
|
|
111
|
-
export declare function poll(ctx:
|
|
112
|
-
signal: AbortSignal;
|
|
113
|
-
}, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
|
|
109
|
+
export declare function poll(ctx: WithSignal, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
|
|
114
110
|
//#endregion
|
|
115
111
|
//#region src/effects/retry.d.ts
|
|
116
112
|
type RetryOptions = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as HandlerRef, C as Emit, D as EventPayload, E as EventLike, F as createBus, M as On, N as WithContext, O as EventsOf, P as
|
|
2
|
-
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, createBus };
|
|
1
|
+
import { A as HandlerRef, B as Keys, C as Emit, D as EventPayload, E as EventLike, F as WithType, H as PayloadOf, I as createBus, J as UnsubscribeCallback, M as On, N as WithContext, O as EventsOf, P as WithSignal, S as ContextOption, T as EventKey, W as Task, _ as Command, b as Context, g as BusOptions, h as Bus, i as WithPayload, j as Off, k as Handler, m as AnyEvent, p as Action, v as CommandCall, w as Emittable, x as ContextOf, y as Commands, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithSignal, type WithType, createBus };
|
package/dist/match.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as EventPayload,
|
|
1
|
+
import { D as EventPayload, J as UnsubscribeCallback, W as Task, h as Bus, p as Action, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
2
|
//#region src/match/plugin.d.ts
|
|
3
3
|
/** A function over the action of an event: `{ type, payload }`. */
|
|
4
4
|
type Predicate<E extends EventMap> = (action: Action<E>) => boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-
|
|
1
|
+
import { H as PayloadOf, J as UnsubscribeCallback, W as Task, _ as Command, b as Context, c as WithScope, h as Bus, o as Scope, v as CommandCall, y as Commands, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
|
+
import { n as ScopeSlots, r as Scoped, t as FieldsOfScope } from "./types-CbdJKC2z.js";
|
|
3
3
|
//#region src/actions/command.d.ts
|
|
4
4
|
/** What `createCommand` returns: a command that also tells whether an action is of its type. */
|
|
5
5
|
type MadeCommand<P, R, T extends string> = Command<P, R> & {
|
|
@@ -159,12 +159,12 @@ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<
|
|
|
159
159
|
* of what `modulePlugin` returns that `devPlugin` wraps.
|
|
160
160
|
*/
|
|
161
161
|
interface ModuleHost {
|
|
162
|
-
mount(
|
|
162
|
+
mount(...modules: Array<{
|
|
163
163
|
readonly name: string;
|
|
164
|
-
}): UnsubscribeCallback;
|
|
165
|
-
unmount(
|
|
164
|
+
}>): UnsubscribeCallback;
|
|
165
|
+
unmount(...modules: Array<{
|
|
166
166
|
readonly name: string;
|
|
167
|
-
}): void;
|
|
167
|
+
}>): void;
|
|
168
168
|
isMounted(module: {
|
|
169
169
|
readonly name: string;
|
|
170
170
|
}): boolean;
|
|
@@ -177,9 +177,14 @@ interface WithApp {
|
|
|
177
177
|
type ModuleApi<E extends EventMap = EventMap> = {
|
|
178
178
|
/** The registry of command handlers of the bus: the one it was made with, or the app's own. */
|
|
179
179
|
commands: Registry<E>;
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Mounts modules, in the order given, and returns the function that unmounts them, last
|
|
182
|
+
* mounted first. A module that is mounted already is not run again. If one of them throws,
|
|
183
|
+
* the ones mounted by this call are unmounted and the error is thrown.
|
|
184
|
+
*/
|
|
185
|
+
mount(...modules: Module<E>[]): UnsubscribeCallback;
|
|
186
|
+
/** Unmounts modules, in reverse order of the arguments. */
|
|
187
|
+
unmount(...modules: Module<E>[]): void;
|
|
183
188
|
isMounted(module: Module<E>): boolean;
|
|
184
189
|
/** Unmounts every module; a disposed app cannot mount modules. */
|
|
185
190
|
dispose(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=e=>({mount:(...t)=>{let[n]=t;if(t.length===1&&n!==void 0)return e.mount(n);let r=[],i=()=>{for(let e of r.splice(0).reverse())e()};try{for(let n of t)e.isMounted(n)||r.push(e.mount(n))}catch(e){throw i(),e}return i},unmount:(...t)=>{for(let n of[...t].reverse())e.unmount(n)},isMounted:e.isMounted});export{e as t};
|
|
@@ -53,6 +53,19 @@ type EventPayload<E extends EventMap> = E[EventKey<E>];
|
|
|
53
53
|
type WithType<K extends string> = {
|
|
54
54
|
type: K;
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* An object that has the `signal` of a task: the context of a task, `{ signal }`, or the
|
|
58
|
+
* `{ signal, abort }` that a starter of `all` and `race` gets. A function that only needs to
|
|
59
|
+
* stop its request when the task is aborted takes `WithSignal`:
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const search = (query: string, { signal }: WithSignal) => fetch(`/search?q=${query}`, { signal });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
type WithSignal = {
|
|
67
|
+
signal: AbortSignal;
|
|
68
|
+
};
|
|
56
69
|
type HandlerRef<E extends EventMap, Response = unknown> = (action: Action<E>) => Response;
|
|
57
70
|
type Handler<E extends EventMap, Response = unknown, K extends EventKey<E> = EventKey<E>> = { [P in K]: {
|
|
58
71
|
type: P;
|
|
@@ -256,12 +269,8 @@ type BusOptions<E extends EventMap> = {
|
|
|
256
269
|
declare const createBus: <Events extends EventMap>(options?: BusOptions<Events>) => Bus<Events>;
|
|
257
270
|
//#endregion
|
|
258
271
|
//#region src/core/effect-types.d.ts
|
|
259
|
-
/** What an effect needs of the task it runs for: its signal. A task context fits, and so does `{ signal }`. */
|
|
260
|
-
type Signaled = {
|
|
261
|
-
signal: AbortSignal;
|
|
262
|
-
};
|
|
263
272
|
/** An effect: a function whose first parameter takes `{ signal }`, like `retry(ctx, fn)`. */
|
|
264
|
-
type SignalFirst = (ctx:
|
|
273
|
+
type SignalFirst = (ctx: WithSignal, ...args: never[]) => unknown;
|
|
265
274
|
/** The effects of a scope or of `effectsPlugin`, by the name they get on the context. */
|
|
266
275
|
type Effects = Record<string, SignalFirst>;
|
|
267
276
|
declare const bound: unique symbol;
|
|
@@ -277,7 +286,7 @@ declare const bound: unique symbol;
|
|
|
277
286
|
* const first: Effect<First> = (ctx, items) => items[0];
|
|
278
287
|
* ```
|
|
279
288
|
*/
|
|
280
|
-
type Effect<F extends (...args: never[]) => unknown> = ((ctx:
|
|
289
|
+
type Effect<F extends (...args: never[]) => unknown> = ((ctx: WithSignal, ...args: Parameters<F>) => ReturnType<F>) & {
|
|
281
290
|
readonly [bound]?: F;
|
|
282
291
|
};
|
|
283
292
|
/** The bound form of a plain effect: the first parameter is gone, and so are its generics. */
|
|
@@ -378,4 +387,4 @@ interface ActionCreator<P = void, T extends string = string, A extends unknown[]
|
|
|
378
387
|
toString(): T;
|
|
379
388
|
}
|
|
380
389
|
//#endregion
|
|
381
|
-
export { On as A, EventKey as C, Handler as D, EventsOf as E,
|
|
390
|
+
export { On as A, EventKey as C, Handler as D, EventsOf as E, EventMap as F, Keys as I, PayloadOf as L, WithSignal as M, WithType as N, HandlerRef as O, createBus as P, Task as R, Emittable as S, EventPayload as T, Commands as _, Scope as a, ContextOption as b, BoundForm as c, Action as d, AnyEvent as f, CommandCall as g, Command as h, WithPayload as i, WithContext as j, Off as k, Effect as l, BusOptions as m, Free as n, WithFields as o, Bus as p, FreeActionCreator as r, WithScope as s, ActionCreator as t, Effects as u, Context as v, EventLike as w, Emit as x, ContextOf as y, UnsubscribeCallback as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as EventKey,
|
|
2
|
-
import { t as BoundOf } from "./plugin-
|
|
1
|
+
import { C as EventKey, F as EventMap, L as PayloadOf, R as Task, _ as Commands, a as Scope, g as CommandCall, h as Command, n as Free, o as WithFields, p as Bus, r as FreeActionCreator, s as WithScope, t as ActionCreator, u as Effects, v as Context, z as UnsubscribeCallback } from "./action-creator-D2CotugT.js";
|
|
2
|
+
import { t as BoundOf } from "./plugin-C6KA4dX-.js";
|
|
3
3
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
4
4
|
//#region src/scope/types.d.ts
|
|
5
5
|
/**
|
|
@@ -341,12 +341,12 @@ type Registry<E extends EventMap> = ReturnType<ReturnType<typeof commandsPlugin<
|
|
|
341
341
|
* of what `modulePlugin` returns that `devPlugin` wraps.
|
|
342
342
|
*/
|
|
343
343
|
interface ModuleHost {
|
|
344
|
-
mount(
|
|
344
|
+
mount(...modules: Array<{
|
|
345
345
|
readonly name: string;
|
|
346
|
-
}): UnsubscribeCallback;
|
|
347
|
-
unmount(
|
|
346
|
+
}>): UnsubscribeCallback;
|
|
347
|
+
unmount(...modules: Array<{
|
|
348
348
|
readonly name: string;
|
|
349
|
-
}): void;
|
|
349
|
+
}>): void;
|
|
350
350
|
isMounted(module: {
|
|
351
351
|
readonly name: string;
|
|
352
352
|
}): boolean;
|
|
@@ -359,9 +359,14 @@ interface WithApp {
|
|
|
359
359
|
type ModuleApi<E extends EventMap = EventMap> = {
|
|
360
360
|
/** The registry of command handlers of the bus: the one it was made with, or the app's own. */
|
|
361
361
|
commands: Registry<E>;
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Mounts modules, in the order given, and returns the function that unmounts them, last
|
|
364
|
+
* mounted first. A module that is mounted already is not run again. If one of them throws,
|
|
365
|
+
* the ones mounted by this call are unmounted and the error is thrown.
|
|
366
|
+
*/
|
|
367
|
+
mount(...modules: Module<E>[]): UnsubscribeCallback;
|
|
368
|
+
/** Unmounts modules, in reverse order of the arguments. */
|
|
369
|
+
unmount(...modules: Module<E>[]): void;
|
|
365
370
|
isMounted(module: Module<E>): boolean;
|
|
366
371
|
/** Unmounts every module; a disposed app cannot mount modules. */
|
|
367
372
|
dispose(): void;
|
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{n as a,r as o}from"./bus-BkUtjPHp.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";const u=Symbol.for(`nanoeffects.scope`),d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(a(s,e,r),n)}let o=Object.assign(i,{type:e,match:r}),s=d(o,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function a(e,t){if(t)return i(o(e),t);let n=e.map(([e,t])=>i(o(e),t));return()=>{for(let e of n)e()}}a(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:a};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(e,t,r,a)=>{let o=e;o[i]=!0;try{S(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,r,i={},o)=>{let l=g(t,r),u=e=>x(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,r,i,a)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,o))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),S(s,f,r,o))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,o):`error`in e?S(s,m,e.error,o):S(s,p,e.value,o))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(a||_(),Reflect.apply(t,null,[r,i]))).then(e=>(v({value:e}),e),e=>{if(l===`idle`)try{_()}catch(e){n(`pending listener`,e)}v({error:e})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,n){return typeof n==`object`?r?_(l,e,n,!1):Reflect.apply(l,null,[e,n]):d(a(T,t,e),o)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,o);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}};function
|
|
1
|
+
import{c as e,i as t,l as n,n as r,s as i}from"./context-yYU3_9lq.js";import{n as a,r as o}from"./bus-BkUtjPHp.js";import{n as s,t as c}from"./lifecycle-key-8iX8RUVD.js";import{t as l}from"./origin-key-BbWN3gmN.js";const u=Symbol.for(`nanoeffects.scope`),d=(e,t)=>(t&&Object.defineProperty(e,u,{value:t}),e),f=(e,t)=>({...e,...t,$effects:{...e.$effects,...t.$effects}}),p=e=>Reflect.get(e,u);function m(e,t,n){let r=typeof t==`function`?t:void 0,i=typeof t==`function`?n:t;return Object.assign(d((...t)=>d({type:e,payload:r?r(...t).payload:t[0]},i),i),{type:e,match:t=>t.type===e,toString:()=>e})}var h=class extends Error{};function g(e,t,n){let r=t=>t.type===e;function i(r,i){if(typeof i==`object`){if(!t)throw new h(`No handler for command "${e}"`);return t(r,i)}return d(a(s,e,r),n)}let o=Object.assign(i,{type:e,match:r}),s=d(o,n);return s}const _=(e,t)=>[e,t],v=e=>typeof Reflect.get(e??{},`handle`)==`function`,y=(e=[])=>t=>{let n=t.commands;if(v(n))return n.handle(e),n;let r=/* @__PURE__ */ new Map,i=(e,t)=>{let n={fn:t};return r.set(e,[...r.get(e)??[],n]),()=>{let t=(r.get(e)??[]).filter(e=>e!==n);t.length>0?r.set(e,t):r.delete(e)}};function a(e,t){if(t)return i(o(e),t);let n=e.map(([e,t])=>i(o(e),t));return()=>{for(let e of n)e()}}a(e);let s={run:(e,t,n)=>{let i=(r.get(e.type)??[]).at(-1)?.fn,a=i&&e.wrap?e.wrap(i):i??e;return Reflect.apply(a,null,[t,n])},handle:a};return t.commands=s,s},b=()=>e=>{function t(t,n){return(...r)=>{let i=t(...r),a=Reflect.get(e,l);a?a(i,n):e.emit(i)}}return Object.assign(e,{emitter:t})},x=e=>typeof e==`string`?m(e):e,S=(e,t,n,r)=>{let i=p(t);e.emit(Reflect.apply(t,null,[n]),r&&i?f(r,i):r)},C=(e,t,r,a)=>{let o=e;o[i]=!0;try{S(e,t,r,a)}catch(e){n(`cancel listener`,e)}o[i]=!1},w=e=>{try{return Promise.resolve(e())}catch(e){if(e instanceof h)throw e;return Promise.reject(e)}},T=(t,r,i={},o)=>{let l=g(t,r),u=e=>x(i[e]??`${t}/${e}`),f=u(`pending`),p=u(`success`),m=u(`fail`),h=u(`cancel`),_=(t,r,i,a)=>{let s=i,l=`idle`,u=()=>{},d=()=>{l=`closed`,u()},g=e=>{l===`started`&&(d(),C(s,h,e,o))},_=()=>{l===`idle`&&(l=`started`,u=e(s,g),S(s,f,r,o))},v=e=>{l===`started`&&(d(),s.signal.aborted?C(s,h,s.signal.reason,o):`error`in e?S(s,m,e.error,o):S(s,p,e.value,o))};return Reflect.set(s,c,{start:_,cancel:g,done:v,drop:()=>{l===`idle`&&(l=`closed`)}}),w(()=>(a||_(),Reflect.apply(t,null,[r,i]))).then(e=>(v({value:e}),e),e=>{if(l===`idle`)try{_()}catch(e){n(`pending listener`,e)}v({error:e})})},v=e=>{let t=Reflect.get(e,s)===!0;return(n,r)=>_(e,n,r,t)};function y(e,n){return typeof n==`object`?r?_(l,e,n,!1):Reflect.apply(l,null,[e,n]):d(a(T,t,e),o)}let b=Object.assign(y,{type:t,match:l.match,wrap:v,pending:f,success:p,fail:m,cancel:h}),T=d(b,o);return T},E=e=>typeof e==`object`&&!!e,D=e=>{if(typeof e==`string`)return e;if(E(e)||typeof e==`function`){let t=Reflect.get(e,`type`);return typeof t==`string`?t:e}return e},O=(e,t)=>{let[n,r]=e;return n===void 0||Object.is(D(n),D(t[0]))&&(r===void 0||Object.is(r,t[1]))},k=e=>{let t={on:e.on,once:e.once,off:e.off},n=[],r=!0,i=(t,n)=>Reflect.apply(t,e,n),a=(e,t)=>(...a)=>{if(!r)return i(t,a);let o={kind:e,args:a,dropped:!1};return n.push(o),()=>{o.live?o.live():o.dropped=!0}},o=e=>(...t)=>{if(!r)return i(e,t);for(let e of n)e.kind!==`off`&&O(t,e.args)&&(e.dropped=!0);n.push({kind:`off`,args:t,dropped:!1})},s=a(`on`,t.on),c=a(`once`,t.once),l=o(t.off);return e.on=s,e.once=c,e.off=l,{release:()=>{r=!1,e.on===s&&(e.on=t.on),e.once===c&&(e.once=t.once),e.off===l&&(e.off=t.off)},replay:()=>{for(let e of n.splice(0))if(!e.dropped){if(e.kind===`off`)i(t.off,e.args);else{let n=e.kind===`on`?t.on:t.once;e.live=i(n,e.args)}}}}},A=e=>({mount:(...t)=>{let[n]=t;if(t.length===1&&n!==void 0)return e.mount(n);let r=[],i=()=>{for(let e of r.splice(0).reverse())e()};try{for(let n of t)e.isMounted(n)||r.push(e.mount(n))}catch(e){throw i(),e}return i},unmount:(...t)=>{for(let n of[...t].reverse())e.unmount(n)},isMounted:e.isMounted});function j(e,t,n){return n?{name:e,setup:t,scope:n}:{name:e,setup:t}}const M=(e,t)=>n=>t?e.fitScope?.(t,n)??n:n,N=(e,t,n)=>{n&&e.applyScope?.(t,n)},P=(e,t,n)=>Array.isArray(t)?[t.map(([t,n])=>[t,e(n)]),n]:[t,e(n)],F=(e,t)=>{let n=e.on;return(...e)=>{let[r,i,...a]=e;return Reflect.apply(n,null,[r,t(i),...a])}},I=e=>(t,...n)=>{e.run(t,...n).catch(t=>{if(!e.signal.aborted)throw t})},L=(i=[])=>a=>{let o=a.commands??y()(a),s={handle:(...e)=>{if(!o.handle)throw Error("modulePlugin: the `commands` of the bus is not a registry from `commandsPlugin()`");return Reflect.apply(o.handle,null,e)}},c=n=>{let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map;return{mount:o=>{let l=r.get(o);if(l)return l;let u=i.get(o.name);u&&r.get(u)?.();let d=t(n,o.name),f=d.ctx,p=c(f),m=()=>{r.delete(o),i.get(o.name)===o&&i.delete(o.name),f.abort(),d.unlink()};r.set(o,m),i.set(o.name,o);let h=o.scope,g=M(a,h),_=(t,n)=>{let r=Reflect.apply(s.handle,null,P(g,t,n));return e(f,r),r},v=(...e)=>{let t=e.map(e=>typeof e==`function`?_(e,e):p.mount(e));return()=>{for(let e of t)e()}},y=I(f),b=F(f,g);try{N(a,f,h),o.setup(Object.assign(f,{handle:_,use:v,spawn:y,on:b}))}catch(e){throw m(),e}return m},unmount:e=>r.get(e)?.(),isMounted:e=>r.has(e)}},l=k(a),u=a.emit,d,f=(e=!0)=>{if(d)return d;l.release(),a.emit===p&&(a.emit=u);let t=r({event:{type:`app`,payload:void 0},bus:a,tracer:a.trace});d={root:t,apps:A(c(t.ctx))};try{e&&d.apps.mount(...i)}finally{l.replay()}return d},p=(...e)=>(f(),Reflect.apply(u,a,e));a.emit=p,i.length>0&&queueMicrotask(()=>{try{f()}catch(e){n(`the modules of the app could not start`,e)}});let m={get commands(){return f(),o},mount:(...e)=>{let{root:t,apps:n}=f();return t.ctx.signal.throwIfAborted(),n.mount(...e)},unmount:(...e)=>f().apps.unmount(...e),isMounted:e=>f().apps.isMounted(e),dispose:()=>f(!1).root.ctx.abort(),createModule:j};return a.app=m,m};export{_ as bindHandler,y as commandsPlugin,m as createAction,g as createCommand,T as createJob,j as createModule,b as emitterPlugin,L as modulePlugin};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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 { F as EventMap, M as WithSignal, R as Task, l as Effect } from "./action-creator-D2CotugT.js";
|
|
2
|
+
import { a as RaceStarter, c as all, d as delay, i as take, l as EffectContext, n as effectsPlugin, o as race, r as TakeOptions, s as allSettled, u as Starter } from "./plugin-C6KA4dX-.js";
|
|
3
3
|
//#region src/utils/onAbort.d.ts
|
|
4
4
|
export declare const onAbort: (ctx: {
|
|
5
5
|
signal?: AbortSignal | undefined;
|
|
@@ -66,9 +66,7 @@ type CancellableExecutor<T> = (handle: CancellableHandle<T>) => void;
|
|
|
66
66
|
* );
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export declare const cancellable: <T = void>(ctx:
|
|
70
|
-
signal: AbortSignal;
|
|
71
|
-
}, executor: CancellableExecutor<T>) => Promise<T>;
|
|
69
|
+
export declare const cancellable: <T = void>(ctx: WithSignal, executor: CancellableExecutor<T>) => Promise<T>;
|
|
72
70
|
//#endregion
|
|
73
71
|
//#region src/effects/poll.d.ts
|
|
74
72
|
type PollOptions = {
|
|
@@ -108,9 +106,7 @@ type PollOptions = {
|
|
|
108
106
|
*/
|
|
109
107
|
type PollMs = number | ((call: number) => number);
|
|
110
108
|
export declare function poll<P, E extends EventMap, R>(ms: PollMs, task: Task<P, E, R>, options?: PollOptions): Task<P, E, Promise<void>>;
|
|
111
|
-
export declare function poll(ctx:
|
|
112
|
-
signal: AbortSignal;
|
|
113
|
-
}, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
|
|
109
|
+
export declare function poll(ctx: WithSignal, fn: (tick: number) => unknown, ms: PollMs, options?: PollOptions): Promise<void>;
|
|
114
110
|
//#endregion
|
|
115
111
|
//#region src/effects/retry.d.ts
|
|
116
112
|
type RetryOptions = {
|
package/dist/notrace/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as On, C as EventKey, D as Handler, E as EventsOf, F as
|
|
2
|
-
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithType, createBus };
|
|
1
|
+
import { A as On, C as EventKey, D as Handler, E as EventsOf, F as EventMap, I as Keys, L as PayloadOf, M as WithSignal, N as WithType, O as HandlerRef, P as createBus, R as Task, S as Emittable, T as EventPayload, _ as Commands, b as ContextOption, d as Action, f as AnyEvent, g as CommandCall, h as Command, i as WithPayload, j as WithContext, k as Off, m as BusOptions, p as Bus, v as Context, w as EventLike, x as Emit, y as ContextOf, z as UnsubscribeCallback } from "./action-creator-D2CotugT.js";
|
|
2
|
+
export { type Action, type AnyEvent, type Bus, type BusOptions, type Command, type CommandCall, type Commands, type Context, type ContextOf, type ContextOption, type Emit, type Emittable, type EventKey, type EventLike, type EventMap, type EventPayload, type EventsOf, type Handler, type HandlerRef, type Keys, type Off, type On, type PayloadOf, type Task, type UnsubscribeCallback, type WithContext, type WithPayload, type WithSignal, type WithType, createBus };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as
|
|
1
|
+
import { F as EventMap, I as Keys, c as BoundForm, j as WithContext, p as Bus, u as Effects, v as Context, y as ContextOf } from "./action-creator-D2CotugT.js";
|
|
2
2
|
//#region src/core/context-types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `unknown` when none of the `fields` is already a context field of the bus,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as EventMap, L as PayloadOf, R as Task } from "./action-creator-D2CotugT.js";
|
|
2
2
|
//#region src/policies/keyed.d.ts
|
|
3
3
|
/** Options shared by every policy that can keep its state per key. */
|
|
4
4
|
type KeyOption<P> = {
|
|
@@ -9,6 +9,14 @@ type KeyOption<P> = {
|
|
|
9
9
|
*/
|
|
10
10
|
key?: (payload: P) => unknown;
|
|
11
11
|
};
|
|
12
|
+
/** Options of a policy called without a task: `key` is left out. */
|
|
13
|
+
type Unkeyed<O> = Omit<O, "key"> & {
|
|
14
|
+
key?: undefined;
|
|
15
|
+
};
|
|
16
|
+
/** Options of a policy called without a task, with a `key` that tells the payload type. */
|
|
17
|
+
type Keyed<O, P> = O & {
|
|
18
|
+
key: (payload: P) => unknown;
|
|
19
|
+
};
|
|
12
20
|
//#endregion
|
|
13
21
|
//#region src/policies/debounce.d.ts
|
|
14
22
|
type DebounceResult<R> = Promise<R | undefined> | Promise<Awaited<R> | undefined> | undefined;
|
|
@@ -18,6 +26,10 @@ type DebounceOptions<P = never> = KeyOption<P> & {
|
|
|
18
26
|
/** Run the last call of a burst after `ms` of quiet. Default `true`. */
|
|
19
27
|
trailing?: boolean;
|
|
20
28
|
};
|
|
29
|
+
/** What `debounce(ms)` returns: it turns a task into a `debounce` task. */
|
|
30
|
+
type DebounceWrapper = <P, E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, DebounceResult<R>>;
|
|
31
|
+
/** What `debounce(ms, { key })` returns: the payload type comes from `key`. */
|
|
32
|
+
type KeyedDebounceWrapper<P> = <E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, DebounceResult<R>>;
|
|
21
33
|
/**
|
|
22
34
|
* Waits for `ms` of quiet, then runs; a new call restarts the wait and drops
|
|
23
35
|
* the previous. With `leading` the first call of a burst runs at once, and the
|
|
@@ -38,14 +50,24 @@ type DebounceOptions<P = never> = KeyOption<P> & {
|
|
|
38
50
|
* bus.emit("input", "re"); // only the last call runs, 300 ms after it
|
|
39
51
|
* ```
|
|
40
52
|
*/
|
|
41
|
-
export declare
|
|
53
|
+
export declare function debounce<P, E extends EventMap, R>(ms: number, fn: Task<P, E, R>, options?: DebounceOptions<P>): Task<P, E, DebounceResult<R>>;
|
|
54
|
+
export declare function debounce(ms: number, options?: Unkeyed<DebounceOptions>): DebounceWrapper;
|
|
55
|
+
export declare function debounce<P>(ms: number, options: Keyed<DebounceOptions<P>, P>): KeyedDebounceWrapper<P>;
|
|
42
56
|
//#endregion
|
|
43
57
|
//#region src/policies/latest.d.ts
|
|
44
58
|
type LatestOptions<P = never> = KeyOption<P>;
|
|
59
|
+
type LatestResult<R> = R | Promise<Awaited<R> | undefined> | undefined;
|
|
60
|
+
/** What `latest()` returns: it turns a task into a `latest` task. */
|
|
61
|
+
type LatestWrapper = <P, E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, LatestResult<R>>;
|
|
62
|
+
/** What `latest({ key })` returns: the payload type comes from `key`. */
|
|
63
|
+
type KeyedLatestWrapper<P> = <E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, LatestResult<R>>;
|
|
45
64
|
/**
|
|
46
65
|
* Aborts the previous run when a new call arrives; stale results are dropped.
|
|
47
66
|
* With `options.key` each key has its own latest run.
|
|
48
67
|
*
|
|
68
|
+
* Called without the task, `latest()` returns a function that takes the task,
|
|
69
|
+
* so `usePolicy(callback, latest())` has no `(task) => ...` to get wrong.
|
|
70
|
+
*
|
|
49
71
|
* @example
|
|
50
72
|
* ```ts
|
|
51
73
|
* bus.on(
|
|
@@ -61,12 +83,21 @@ type LatestOptions<P = never> = KeyOption<P>;
|
|
|
61
83
|
*
|
|
62
84
|
* // one latest run per user instead of one for all
|
|
63
85
|
* bus.on("load", latest(loadUser, { key: (user) => user.id }));
|
|
86
|
+
*
|
|
87
|
+
* // without the task: for a hook that builds the task itself
|
|
88
|
+
* const search = usePolicy(runSearch, latest());
|
|
64
89
|
* ```
|
|
65
90
|
*/
|
|
66
|
-
export declare
|
|
91
|
+
export declare function latest<P, E extends EventMap, R>(fn: Task<P, E, R>, options?: LatestOptions<P>): Task<P, E, LatestResult<R>>;
|
|
92
|
+
export declare function latest(options?: Unkeyed<LatestOptions>): LatestWrapper;
|
|
93
|
+
export declare function latest<P>(options: Keyed<LatestOptions<P>, P>): KeyedLatestWrapper<P>;
|
|
67
94
|
//#endregion
|
|
68
95
|
//#region src/policies/leading.d.ts
|
|
69
96
|
type LeadingOptions<P = never> = KeyOption<P>;
|
|
97
|
+
/** What `leading()` returns: it turns a task into a `leading` task. */
|
|
98
|
+
type LeadingWrapper = <P, E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, R | Promise<Awaited<R>> | undefined>;
|
|
99
|
+
/** What `leading({ key })` returns: the payload type comes from `key`. */
|
|
100
|
+
type KeyedLeadingWrapper<P> = <E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, R | Promise<Awaited<R>> | undefined>;
|
|
70
101
|
/**
|
|
71
102
|
* Drops new calls while the task is still running. The lock is released when
|
|
72
103
|
* the run settles or when its task is aborted, whichever comes first, so a
|
|
@@ -86,7 +117,9 @@ type LeadingOptions<P = never> = KeyOption<P>;
|
|
|
86
117
|
* bus.emit("save", draft); // dropped while the first save is in flight
|
|
87
118
|
* ```
|
|
88
119
|
*/
|
|
89
|
-
export declare
|
|
120
|
+
export declare function leading<P, E extends EventMap, R>(fn: Task<P, E, R>, options?: LeadingOptions<P>): Task<P, E, R | Promise<Awaited<R>> | undefined>;
|
|
121
|
+
export declare function leading(options?: Unkeyed<LeadingOptions>): LeadingWrapper;
|
|
122
|
+
export declare function leading<P>(options: Keyed<LeadingOptions<P>, P>): KeyedLeadingWrapper<P>;
|
|
90
123
|
//#endregion
|
|
91
124
|
//#region src/policies/queue.d.ts
|
|
92
125
|
type QueueOptions<P = never> = KeyOption<P> & {
|
|
@@ -101,6 +134,10 @@ type QueueOptions<P = never> = KeyOption<P> & {
|
|
|
101
134
|
*/
|
|
102
135
|
overflow?: "drop-new" | "drop-old";
|
|
103
136
|
};
|
|
137
|
+
/** What `queue()` returns: it turns a task into a `queue` task. */
|
|
138
|
+
type QueueWrapper = <P, E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, Promise<Awaited<R> | undefined>>;
|
|
139
|
+
/** What `queue({ key })` returns: the payload type comes from `key`. */
|
|
140
|
+
type KeyedQueueWrapper<P> = <E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, Promise<Awaited<R> | undefined>>;
|
|
104
141
|
/**
|
|
105
142
|
* Runs calls one after another, in the order they arrived: a call starts when
|
|
106
143
|
* fewer than `concurrency` calls are running. Every call returns a promise with
|
|
@@ -131,7 +168,9 @@ type QueueOptions<P = never> = KeyOption<P> & {
|
|
|
131
168
|
* bus.emit("save", b); // waits for a, then runs
|
|
132
169
|
* ```
|
|
133
170
|
*/
|
|
134
|
-
export declare
|
|
171
|
+
export declare function queue<P, E extends EventMap, R>(fn: Task<P, E, R>, options?: QueueOptions<P>): Task<P, E, Promise<Awaited<R> | undefined>>;
|
|
172
|
+
export declare function queue(options?: Unkeyed<QueueOptions>): QueueWrapper;
|
|
173
|
+
export declare function queue<P>(options: Keyed<QueueOptions<P>, P>): KeyedQueueWrapper<P>;
|
|
135
174
|
//#endregion
|
|
136
175
|
//#region src/policies/throttle.d.ts
|
|
137
176
|
type ThrottleOptions<P = never> = KeyOption<P> & {
|
|
@@ -140,6 +179,10 @@ type ThrottleOptions<P = never> = KeyOption<P> & {
|
|
|
140
179
|
/** Run the latest call made while waiting, at the end of the window. Default `true`. */
|
|
141
180
|
trailing?: boolean;
|
|
142
181
|
};
|
|
182
|
+
/** What `throttle(ms)` returns: it turns a task into a `throttle` task. */
|
|
183
|
+
type ThrottleWrapper = <P, E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, R | Promise<R | undefined> | undefined>;
|
|
184
|
+
/** What `throttle(ms, { key })` returns: the payload type comes from `key`. */
|
|
185
|
+
type KeyedThrottleWrapper<P> = <E extends EventMap, R>(fn: Task<P, E, R>) => Task<P, E, R | Promise<R | undefined> | undefined>;
|
|
143
186
|
/**
|
|
144
187
|
* At most one run per `ms`, with the semantics of lodash `throttle` (and
|
|
145
188
|
* patronum): a call made when the throttle is idle, that is, at least `ms`
|
|
@@ -166,7 +209,9 @@ type ThrottleOptions<P = never> = KeyOption<P> & {
|
|
|
166
209
|
* bus.emit("scroll", 30); // runs once the 200 ms window closes
|
|
167
210
|
* ```
|
|
168
211
|
*/
|
|
169
|
-
export declare
|
|
212
|
+
export declare function throttle<P, E extends EventMap, R>(ms: number, fn: Task<P, E, R>, options?: ThrottleOptions<P>): Task<P, E, R | Promise<R | undefined> | undefined>;
|
|
213
|
+
export declare function throttle(ms: number, options?: Unkeyed<ThrottleOptions>): ThrottleWrapper;
|
|
214
|
+
export declare function throttle<P>(ms: number, options: Keyed<ThrottleOptions<P>, P>): KeyedThrottleWrapper<P>;
|
|
170
215
|
//#endregion
|
|
171
216
|
//#region src/policies/with-policy.d.ts
|
|
172
217
|
/** What `withPolicy` returns: the task as a plain function that can be cancelled. */
|
package/dist/notrace/policies.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,i as n,n as r,o as i,t as a}from"./context-yYU3_9lq.js";import{n as o,r as s,t as c}from"./delay-BosJKFjg.js";import{n as l,t as u}from"./promise-CSLpzwSR.js";import{n as d,t as f}from"./lifecycle-key-8iX8RUVD.js";const p=e=>Reflect.get(e,f),m=e=>{p(e)?.start()},h=(t,n,r)=>(m(t),e(t,n,r)),g=(e,t)=>{i(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,d,!0),e),b=()=>{},x=(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)}},
|
|
1
|
+
import{a as e,c as t,i as n,n as r,o as i,t as a}from"./context-yYU3_9lq.js";import{n as o,r as s,t as c}from"./delay-BosJKFjg.js";import{n as l,t as u}from"./promise-CSLpzwSR.js";import{n as d,t as f}from"./lifecycle-key-8iX8RUVD.js";const p=e=>Reflect.get(e,f),m=e=>{p(e)?.start()},h=(t,n,r)=>(m(t),e(t,n,r)),g=(e,t)=>{i(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,d,!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,r,o=b)=>{let s=null;return(c,u)=>{if(s?.abort(),u.signal.aborted)return;let{ctx:d,unlink:f}=n(u);s=d;let p=a(d,e),h=!1,g=()=>{d.signal.aborted||(h=!0,m(d),i(d,e,`start`))};t(d,e=>{v(d,h,e),p(h?`cancel`:`drop`)});let _=()=>{f(),s===d&&(s=null,o())},y=e=>{if(!d.signal.aborted)return p(h?`done`:`drop`),e};try{let e=r(c,d,g);return l(e)?Promise.resolve(e).then(y,e=>{if(!d.signal.aborted)throw p(`error`,e),e}).finally(_):(_(),y(e))}catch(e){if(_(),d.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=(e,t,n,r)=>{let i=r!==b,a=null,c=null;return(l,u)=>{if(u.signal.aborted)return;let d=Date.now(),f=a===null||d-a>=e||d-a<0;return a=d,c!==null&&o(c),c=i?s(r,e):null,n&&f?Promise.resolve(h(u,`debounce`,()=>t(l,u))):(g(u,`debounce`),Promise.resolve(void 0))}},A=(e,n,r,i)=>{let a=r.leading??!1,o=r.trailing??!0;if(!o)return k(e,n,a,i);let s=!1,l=0,u=E(`debounce`,([r,i],a,u)=>{let d=l;return t(a,()=>{l===d&&(s=!1)}),c(a,e).then(()=>{if(s=!1,o&&!i)return u(),n(r,a)})},i);return(e,t)=>{if(t.signal.aborted)return;let r=a&&!s;s=!0,l++;let i=u([e,r],t);return r?Promise.resolve(h(t,`debounce`,()=>n(e,t))):i}};function j(e,t){return x(e,t,M)}const M=(e,n)=>C(n.key,n=>{let r=null;return(i,a)=>{if(a.signal.aborted)return;if(r){g(a,`leading`);return}let o={};r=o;let s=()=>{c(),r===o&&(r=null,n())},c=t(a,s);try{return u(h(a,`leading`,()=>e(i,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,n,r)=>{let i=n.concurrency??1,a=n.limit??1/0,o=[],s=0,c=()=>{for(;s<i;){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 n=!0,i=()=>{n&&(n=!1,s--,c(),s===0&&o.length===0&&r())},a=t(u,()=>{i(),d(void 0)}),g;try{g=Promise.resolve(h(u,`queue`,()=>e(l,u)))}catch(e){g=Promise.reject(e)}let v=()=>{a(),i()};g.then(e=>{_(u,{value:e}),v(),d(u.signal.aborted?void 0:e)},e=>{_(u,{error:e}),v(),u.signal.aborted?d(void 0):f(e)})};if(s<i){v();return}if(o.length>=a){if(n.overflow!==`drop-old`||a<=0){m();return}o.shift()?.drop()}let y={start:v,drop:m};o.push(y),p=t(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=(e,t,n,r)=>{let i=n.leading??!0,a=n.trailing??!0,c=r!==b,l=null,u=0,d=null,f=null,p=null,m=!1,_=t=>l===null||t-l>=e||t-l<0||t-u>=e,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,n,r)=>{y(),u=r,m=!0;try{return h(n,`throttle`,()=>t(e,n))}finally{m=!1}},C=()=>{c&&(f=s(w,e))},w=()=>{if(f=null,!c||d!==null||p)return;let t=Date.now(),n=Math.max(e-(t-(l??-1/0)),e-(t-u));n<=0?r():f=s(w,n)},T=e=>{d=null;let t=p;if(a&&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 t=Date.now();_(t)?T(t):d=s(E,Math.min(e-(t-(l??t)),e-(t-u)))},D=()=>{f!==null&&(o(f),f=null)},O=(e,t)=>{if(!a)v(t);else return x(e,t)},k=(e,t,n,r)=>{if(!r)v(t);else if(u=n,C(),!i)v(t);else return S(e,t,n)},A=(t,n,r,a)=>a&&d!==null?(o(d),d=s(E,e),S(t,n,r)):d===null&&(d=s(E,e),a&&(u=r,i))?S(t,n,r):O(t,n);return(e,t)=>{if(t.signal.aborted)return;let n=Date.now(),r=!m&&_(n);return l=n,D(),a?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 i=n[0],{ctx:a,unlink:o}=r({event:{type:`withPolicy`,payload:i},parent:{signal:t.signal}});try{return await e(i,a)}finally{o()}},i=e=>{t.abort(e),t=new AbortController},a=Object.assign(n,{cancel:i});return z&&Reflect.set(a,z,()=>i()),a};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 { F as EventMap, p as Bus } from "./action-creator-D2CotugT.js";
|
|
2
2
|
import { t as OriginOptions } from "./origin-key-CxK0SkeG.js";
|
|
3
3
|
//#region src/store/redux/middleware.d.ts
|
|
4
4
|
/** What Redux passes through a middleware: an action is a plain object with a `type`. */
|
package/dist/observable.d.ts
CHANGED
package/dist/oop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as ListenerOptions, _ as Command, h as Bus, t as ActionCreator, z as EventMap } from "./action-creator-Bpa8BUS9.js";
|
|
2
2
|
//#region src/oop/types.d.ts
|
|
3
3
|
type Slots = "ctx" | "commands" | "trace" | "addContext" | "applyScope" | "fitScope" | "app" | "use";
|
|
4
4
|
type AnyFunction = (...args: never[]) => unknown;
|