rexfect 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1756 -0
- package/dist/abortableContext.d.ts +3 -0
- package/dist/abortableContext.d.ts.map +1 -0
- package/dist/abortableContext.js +48 -0
- package/dist/abortableContext.js.map +1 -0
- package/dist/action.d.ts +64 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +208 -0
- package/dist/action.js.map +1 -0
- package/dist/action.test.d.ts +2 -0
- package/dist/action.test.d.ts.map +1 -0
- package/dist/action.test.js +189 -0
- package/dist/action.test.js.map +1 -0
- package/dist/async/abortable-guard.d.ts +25 -0
- package/dist/async/abortable-guard.d.ts.map +1 -0
- package/dist/async/abortable-guard.js +33 -0
- package/dist/async/abortable-guard.js.map +1 -0
- package/dist/async/abortable.d.ts +331 -0
- package/dist/async/abortable.d.ts.map +1 -0
- package/dist/async/abortable.js +410 -0
- package/dist/async/abortable.js.map +1 -0
- package/dist/async/abortable.test.d.ts +2 -0
- package/dist/async/abortable.test.d.ts.map +1 -0
- package/dist/async/abortable.test.js +535 -0
- package/dist/async/abortable.test.js.map +1 -0
- package/dist/async/abortable.typeCheck.d.ts +8 -0
- package/dist/async/abortable.typeCheck.d.ts.map +1 -0
- package/dist/async/abortable.typeCheck.js +138 -0
- package/dist/async/abortable.typeCheck.js.map +1 -0
- package/dist/async/async.d.ts +18 -0
- package/dist/async/async.d.ts.map +1 -0
- package/dist/async/async.js +20 -0
- package/dist/async/async.js.map +1 -0
- package/dist/async/index.d.ts +15 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +13 -0
- package/dist/async/index.js.map +1 -0
- package/dist/async/loadable.d.ts +7 -0
- package/dist/async/loadable.d.ts.map +1 -0
- package/dist/async/loadable.js +52 -0
- package/dist/async/loadable.js.map +1 -0
- package/dist/async/loadable.test.d.ts +2 -0
- package/dist/async/loadable.test.d.ts.map +1 -0
- package/dist/async/loadable.test.js +322 -0
- package/dist/async/loadable.test.js.map +1 -0
- package/dist/async/promiseCache.d.ts +14 -0
- package/dist/async/promiseCache.d.ts.map +1 -0
- package/dist/async/promiseCache.js +29 -0
- package/dist/async/promiseCache.js.map +1 -0
- package/dist/async/read.d.ts +120 -0
- package/dist/async/read.d.ts.map +1 -0
- package/dist/async/read.js +286 -0
- package/dist/async/read.js.map +1 -0
- package/dist/async/read.test.d.ts +2 -0
- package/dist/async/read.test.d.ts.map +1 -0
- package/dist/async/read.test.js +419 -0
- package/dist/async/read.test.js.map +1 -0
- package/dist/async/read.typeCheck.d.ts +6 -0
- package/dist/async/read.typeCheck.d.ts.map +1 -0
- package/dist/async/read.typeCheck.js +101 -0
- package/dist/async/read.typeCheck.js.map +1 -0
- package/dist/async/safe.d.ts +230 -0
- package/dist/async/safe.d.ts.map +1 -0
- package/dist/async/safe.js +247 -0
- package/dist/async/safe.js.map +1 -0
- package/dist/async/safe.test.d.ts +2 -0
- package/dist/async/safe.test.d.ts.map +1 -0
- package/dist/async/safe.test.js +447 -0
- package/dist/async/safe.test.js.map +1 -0
- package/dist/async/utils.d.ts +17 -0
- package/dist/async/utils.d.ts.map +1 -0
- package/dist/async/utils.js +38 -0
- package/dist/async/utils.js.map +1 -0
- package/dist/async/wait.d.ts +120 -0
- package/dist/async/wait.d.ts.map +1 -0
- package/dist/async/wait.js +112 -0
- package/dist/async/wait.js.map +1 -0
- package/dist/async/wait.test.d.ts +2 -0
- package/dist/async/wait.test.d.ts.map +1 -0
- package/dist/async/wait.test.js +122 -0
- package/dist/async/wait.test.js.map +1 -0
- package/dist/async/wait.typeCheck.d.ts +6 -0
- package/dist/async/wait.typeCheck.d.ts.map +1 -0
- package/dist/async/wait.typeCheck.js +104 -0
- package/dist/async/wait.typeCheck.js.map +1 -0
- package/dist/atom.d.ts +46 -0
- package/dist/atom.d.ts.map +1 -0
- package/dist/atom.js +86 -0
- package/dist/atom.js.map +1 -0
- package/dist/atom.test.d.ts +2 -0
- package/dist/atom.test.d.ts.map +1 -0
- package/dist/atom.test.js +75 -0
- package/dist/atom.test.js.map +1 -0
- package/dist/batch.d.ts +15 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/batch.js +45 -0
- package/dist/batch.js.map +1 -0
- package/dist/defer.d.ts +56 -0
- package/dist/defer.d.ts.map +1 -0
- package/dist/defer.js +49 -0
- package/dist/defer.js.map +1 -0
- package/dist/effect.d.ts +91 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/effect.js +311 -0
- package/dist/effect.js.map +1 -0
- package/dist/effect.test.d.ts +2 -0
- package/dist/effect.test.d.ts.map +1 -0
- package/dist/effect.test.js +123 -0
- package/dist/effect.test.js.map +1 -0
- package/dist/emitter.d.ts +129 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +164 -0
- package/dist/emitter.js.map +1 -0
- package/dist/emitter.test.d.ts +2 -0
- package/dist/emitter.test.d.ts.map +1 -0
- package/dist/emitter.test.js +259 -0
- package/dist/emitter.test.js.map +1 -0
- package/dist/equality.d.ts +66 -0
- package/dist/equality.d.ts.map +1 -0
- package/dist/equality.js +145 -0
- package/dist/equality.js.map +1 -0
- package/dist/event.d.ts +18 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +166 -0
- package/dist/event.js.map +1 -0
- package/dist/event.test.d.ts +2 -0
- package/dist/event.test.d.ts.map +1 -0
- package/dist/event.test.js +167 -0
- package/dist/event.test.js.map +1 -0
- package/dist/hooks.d.ts +152 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +122 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks.test.d.ts +2 -0
- package/dist/hooks.test.d.ts.map +1 -0
- package/dist/hooks.test.js +99 -0
- package/dist/hooks.test.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/isPromiseLike.d.ts +10 -0
- package/dist/isPromiseLike.d.ts.map +1 -0
- package/dist/isPromiseLike.js +15 -0
- package/dist/isPromiseLike.js.map +1 -0
- package/dist/pick.d.ts +22 -0
- package/dist/pick.d.ts.map +1 -0
- package/dist/pick.js +46 -0
- package/dist/pick.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +8 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useRx.d.ts +14 -0
- package/dist/react/useRx.d.ts.map +1 -0
- package/dist/react/useRx.js +110 -0
- package/dist/react/useRx.js.map +1 -0
- package/dist/react/useRx.test.d.ts +2 -0
- package/dist/react/useRx.test.d.ts.map +1 -0
- package/dist/react/useRx.test.js +457 -0
- package/dist/react/useRx.test.js.map +1 -0
- package/dist/strictModeTest.d.ts +11 -0
- package/dist/strictModeTest.d.ts.map +1 -0
- package/dist/strictModeTest.js +41 -0
- package/dist/strictModeTest.js.map +1 -0
- package/dist/types.d.ts +606 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/untrack.d.ts +14 -0
- package/dist/untrack.d.ts.map +1 -0
- package/dist/untrack.js +17 -0
- package/dist/untrack.js.map +1 -0
- package/dist/utils/withUse.d.ts +10 -0
- package/dist/utils/withUse.d.ts.map +1 -0
- package/dist/utils/withUse.js +21 -0
- package/dist/utils/withUse.js.map +1 -0
- package/dist/utils/withUse.test.d.ts +2 -0
- package/dist/utils/withUse.test.d.ts.map +1 -0
- package/dist/utils/withUse.test.js +233 -0
- package/dist/utils/withUse.test.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +7 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +119 -0
- package/dist/utils.test.js.map +1 -0
- package/package.json +64 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic function type for any function signature.
|
|
3
|
+
* Used internally for type constraints.
|
|
4
|
+
*/
|
|
5
|
+
export type AnyFunc = (...args: any[]) => any;
|
|
6
|
+
/**
|
|
7
|
+
* A reactive signal that holds a value.
|
|
8
|
+
*
|
|
9
|
+
* Signals are the read-only part of atoms. They:
|
|
10
|
+
* - Return current value when called as a function
|
|
11
|
+
* - Auto-track dependencies when read inside effect() or useRx()
|
|
12
|
+
* - Allow subscription to changes via .on()
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of value the signal holds
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const [count, setCount] = atom(0);
|
|
19
|
+
* // count is Signal<number>
|
|
20
|
+
*
|
|
21
|
+
* count(); // Read: 0
|
|
22
|
+
* count.on(v => console.log(v)); // Subscribe
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type Signal<T = any> = {
|
|
26
|
+
/**
|
|
27
|
+
* Get current value.
|
|
28
|
+
* When called inside effect() or useRx(), creates a dependency -
|
|
29
|
+
* the effect/component will re-run when this signal changes.
|
|
30
|
+
*/
|
|
31
|
+
(): T;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to value changes.
|
|
34
|
+
* @param listener - Called with new value whenever signal changes
|
|
35
|
+
* @returns Unsubscribe function - call to stop receiving updates
|
|
36
|
+
*/
|
|
37
|
+
on(listener: (value: T) => void): VoidFunction;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A setter function for updating atom value.
|
|
41
|
+
*
|
|
42
|
+
* @template T - The type of value to set
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const [count, setCount] = atom(0);
|
|
47
|
+
* setCount(5); // Set to 5
|
|
48
|
+
* setCount(c => c + 1); // Functional update (if supported)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type Setter<T = any> = (value: T) => void;
|
|
52
|
+
/**
|
|
53
|
+
* A getter function that returns a value.
|
|
54
|
+
* Used for read-only access patterns.
|
|
55
|
+
*
|
|
56
|
+
* @template T - The type of value returned
|
|
57
|
+
*/
|
|
58
|
+
export type Getter<T = any> = () => T;
|
|
59
|
+
/**
|
|
60
|
+
* Tuple type returned by atom() - [getter, setter] pair.
|
|
61
|
+
* Similar to React's useState return type.
|
|
62
|
+
*
|
|
63
|
+
* @template T - The type of value in the atom
|
|
64
|
+
*/
|
|
65
|
+
export type Tuple<T = any> = readonly [getter: Getter<T>, setter: Setter<T>];
|
|
66
|
+
/**
|
|
67
|
+
* Mapper function that transforms a source signal into a destination signal.
|
|
68
|
+
* Used for signal-only transformations in atom.use().
|
|
69
|
+
*
|
|
70
|
+
* @template S - Source signal type
|
|
71
|
+
* @template D - Destination signal type
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const mapper: SignalMapper<Signal<number>, Signal<string>> = (s) => () => s().toString();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export type SignalMapper<S extends Signal<any>, D extends Signal<any>> = (origin: S) => D;
|
|
79
|
+
/**
|
|
80
|
+
* Mapper function that transforms a source setter into a destination setter.
|
|
81
|
+
* Used for setter-only transformations in atom.use().
|
|
82
|
+
*
|
|
83
|
+
* @template S - Source setter type
|
|
84
|
+
* @template D - Destination setter type
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const mapper: SetterMapper<Setter<{a: number}>, Setter<string>> =
|
|
89
|
+
* (set) => (value: string) => set({ a: Number(value) });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export type SetterMapper<S extends Setter<any>, D extends Setter<any>> = (origin: S) => D;
|
|
93
|
+
/**
|
|
94
|
+
* Options for atom.use() transformations.
|
|
95
|
+
* Supports three patterns:
|
|
96
|
+
* 1. Setter-only: Pass a SetterMapper function directly
|
|
97
|
+
* 2. Signal + Setter: Pass object with `sig` and optional `set` properties
|
|
98
|
+
* 3. Signal-only: Pass object with only `sig` property
|
|
99
|
+
*
|
|
100
|
+
* @template TSignal - Original signal type
|
|
101
|
+
* @template TSetter - Original setter type
|
|
102
|
+
* @template TNewSignal - New signal type (defaults to TSignal)
|
|
103
|
+
* @template TNewSetter - New setter type (defaults to TSetter)
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* // Setter-only transformation
|
|
108
|
+
* atom({a: 0}).use((set) => (value: string) => set({ a: Number(value) }));
|
|
109
|
+
*
|
|
110
|
+
* // Signal + setter transformation
|
|
111
|
+
* atom({a: 0, b: 0}).use({
|
|
112
|
+
* sig: (s) => () => s().a,
|
|
113
|
+
* set: (set) => (value: number) => set({ a: value, b: 0 })
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Signal-only transformation
|
|
117
|
+
* atom({a: 0}).use({
|
|
118
|
+
* sig: (s) => () => s().a
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export type UseOptions<TSignal extends Signal<any>, TSetter extends Setter<any>, TNewSignal extends Signal<any> = TSignal, TNewSetter extends Setter<any> = TSetter> = SetterMapper<TSetter, TNewSetter> | {
|
|
123
|
+
sig: SignalMapper<TSignal, TNewSignal>;
|
|
124
|
+
set?: SetterMapper<TSetter, TNewSetter>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Adds .use() method to a tuple of [Signal, Setter].
|
|
128
|
+
* The tuple remains destructureable while gaining transformation capabilities.
|
|
129
|
+
*
|
|
130
|
+
* @template T - Tuple type [Signal<any>, Setter<any>]
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const mappable: WithUse<[Signal<number>, Setter<number>]> = withUse([s, set]);
|
|
135
|
+
* const [s, set] = mappable; // Still destructureable
|
|
136
|
+
* const transformed = mappable.use((setter, signal) => ({ set: (v: string) => setter(Number(v)) })); // Chainable
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export type WithUse<T extends readonly [Signal<any>, Setter<any>]> = {
|
|
140
|
+
/**
|
|
141
|
+
* Apply a plugin to the atom's signal and/or setter.
|
|
142
|
+
* Plugins can transform types, add listeners, or enhance behavior.
|
|
143
|
+
* Returns a new withUse tuple that can be chained further.
|
|
144
|
+
*
|
|
145
|
+
* @param plugin - Plugin function that receives setter and signal and returns an object with optional sig and set properties, or void for side effects only
|
|
146
|
+
* @returns New withUse tuple with potentially modified signal/setter
|
|
147
|
+
*/
|
|
148
|
+
use<TNewSignal extends Signal<any> = T[0], TNewSetter extends Setter<any> = T[1]>(plugin: (signal: T[0], setter: T[1]) => {
|
|
149
|
+
sig?: TNewSignal;
|
|
150
|
+
set?: TNewSetter;
|
|
151
|
+
} | void): WithUse<readonly [TNewSignal, TNewSetter]>;
|
|
152
|
+
} & T;
|
|
153
|
+
/**
|
|
154
|
+
* A mappable atom - a tuple of [Signal, Setter] with .use() method for transformations.
|
|
155
|
+
* Can be destructured normally or used with .use() for chaining transformations.
|
|
156
|
+
*
|
|
157
|
+
* @template T - The type of value stored in the atom
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const atomValue: Atom<number> = atom(1);
|
|
162
|
+
* const [signal, setter] = atomValue; // Destructureable
|
|
163
|
+
* const transformed = atomValue.use((set, sig) => [sig, (v: string) => set(Number(v))]); // Chainable
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export type Atom<T> = WithUse<readonly [Signal<T>, Setter<T>]>;
|
|
167
|
+
/**
|
|
168
|
+
* Options for creating an atom.
|
|
169
|
+
*
|
|
170
|
+
* @template T - The type of value the atom holds
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const [user, setUser] = atom(userData, {
|
|
175
|
+
* equals: "shallow", // Only notify if properties changed
|
|
176
|
+
* key: "currentUser", // For debugging
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export interface AtomOptions<T> {
|
|
181
|
+
/**
|
|
182
|
+
* Equality function to determine if value has changed.
|
|
183
|
+
* If values are "equal", subscribers won't be notified.
|
|
184
|
+
*
|
|
185
|
+
* - `"strict"` (default): Object.is comparison
|
|
186
|
+
* - `"shallow"`: Compare object keys/array length, Object.is per item
|
|
187
|
+
* - `"shallow2"`: 2 levels deep
|
|
188
|
+
* - `"shallow3"`: 3 levels deep
|
|
189
|
+
* - `"deep"`: Full recursive comparison
|
|
190
|
+
* - `(a, b) => boolean`: Custom comparison function
|
|
191
|
+
*/
|
|
192
|
+
equals?: Equality<T>;
|
|
193
|
+
/**
|
|
194
|
+
* Debug key for identifying this atom in dev tools or logs.
|
|
195
|
+
*/
|
|
196
|
+
key?: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Options for creating an action.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* const onAppInit = action<Config>({
|
|
204
|
+
* sealed: true, // Only fires once
|
|
205
|
+
* key: "appInit",
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export interface ActionOptions {
|
|
210
|
+
/**
|
|
211
|
+
* Debug key for identifying this action in dev tools or logs.
|
|
212
|
+
*/
|
|
213
|
+
key?: string;
|
|
214
|
+
/**
|
|
215
|
+
* If true, action "seals" after first dispatch:
|
|
216
|
+
* - Subsequent dispatches become no-ops (listeners don't fire)
|
|
217
|
+
* - Late subscribers receive the last payload immediately
|
|
218
|
+
*
|
|
219
|
+
* Useful for one-time initialization patterns.
|
|
220
|
+
*/
|
|
221
|
+
sealed?: boolean;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Options for effect().
|
|
225
|
+
*/
|
|
226
|
+
export interface EffectOptions {
|
|
227
|
+
/**
|
|
228
|
+
* Debug key for identifying this effect in dev tools or logs.
|
|
229
|
+
*/
|
|
230
|
+
key?: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Base context with plugin system.
|
|
234
|
+
*
|
|
235
|
+
* The `use()` method allows extending context functionality via plugins.
|
|
236
|
+
* Plugins receive the context and can return additional utilities.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* const withRetry = (ctx, maxRetries) => ({
|
|
241
|
+
* async fetch(url) {
|
|
242
|
+
* for (let i = 0; i < maxRetries; i++) {
|
|
243
|
+
* try { return await fetch(url, { signal: ctx.signal }); }
|
|
244
|
+
* catch (e) { if (i === maxRetries - 1) throw e; }
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* action.on((payload, ctx) => {
|
|
250
|
+
* const { fetch } = ctx.use(withRetry, 3);
|
|
251
|
+
* await fetch('/api/data');
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export interface UsableContext {
|
|
256
|
+
/**
|
|
257
|
+
* Apply a plugin to extend context functionality.
|
|
258
|
+
*
|
|
259
|
+
* @param fn - Plugin function that receives context and returns utilities
|
|
260
|
+
* @param args - Additional arguments passed to the plugin
|
|
261
|
+
* @returns Whatever the plugin returns
|
|
262
|
+
*/
|
|
263
|
+
use<R, Args extends any[]>(fn: (context: this, ...args: Args) => R, ...args: Args): R;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Context with abort/cancellation capabilities.
|
|
267
|
+
*
|
|
268
|
+
* Provides utilities for cancelling async operations:
|
|
269
|
+
* - `signal` for passing to fetch, AbortController-aware APIs
|
|
270
|
+
* - `safe()` for ignoring results after abort
|
|
271
|
+
* - `abortPrev()` for cancelling previous invocation (latest-only pattern)
|
|
272
|
+
* - `fork()`/`spawn()` for child contexts
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* async function fetchData(ctx: AbortableContext) {
|
|
277
|
+
* const res = await fetch('/api', { signal: ctx.signal });
|
|
278
|
+
* return ctx.safe(res.json()); // Ignored if aborted
|
|
279
|
+
* }
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* // Latest-only pattern with abortPrev
|
|
285
|
+
* const search = abortable(async ({ signal, abortPrev }, query: string) => {
|
|
286
|
+
* abortPrev(); // Cancel previous search
|
|
287
|
+
* const res = await fetch(`/search?q=${query}`, { signal });
|
|
288
|
+
* return res.json();
|
|
289
|
+
* });
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export interface AbortableContext extends UsableContext {
|
|
293
|
+
/**
|
|
294
|
+
* AbortSignal for this context.
|
|
295
|
+
* Pass to fetch, axios, or any AbortController-aware API.
|
|
296
|
+
* Becomes aborted when abort() is called.
|
|
297
|
+
*/
|
|
298
|
+
signal: AbortSignal;
|
|
299
|
+
/**
|
|
300
|
+
* Abort this context.
|
|
301
|
+
* Sets signal.aborted to true and triggers abort event.
|
|
302
|
+
*/
|
|
303
|
+
abort(): void;
|
|
304
|
+
/**
|
|
305
|
+
* Abort the previous invocation of this abortable function.
|
|
306
|
+
* Useful for "latest only" patterns where rapid calls should cancel in-flight operations.
|
|
307
|
+
*
|
|
308
|
+
* @param message - Optional abort message
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* const search = abortable(async ({ signal, abortPrev }, query: string) => {
|
|
313
|
+
* abortPrev(); // Cancel previous search
|
|
314
|
+
* const res = await fetch(`/search?q=${query}`, { signal });
|
|
315
|
+
* return res.json();
|
|
316
|
+
* });
|
|
317
|
+
*
|
|
318
|
+
* search("h");
|
|
319
|
+
* search("he");
|
|
320
|
+
* const results = await search("hello"); // Only this completes
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
abortPrev(message?: string): void;
|
|
324
|
+
/**
|
|
325
|
+
* Wrap a promise to ignore its result if context is aborted.
|
|
326
|
+
* If aborted, returns a promise that never resolves/rejects.
|
|
327
|
+
*
|
|
328
|
+
* @param promise - Promise to wrap
|
|
329
|
+
* @returns Promise that ignores result if aborted
|
|
330
|
+
*/
|
|
331
|
+
safe<T>(promise: PromiseLike<T>): Promise<T>;
|
|
332
|
+
/**
|
|
333
|
+
* Wrap a callback to no-op if context is aborted.
|
|
334
|
+
* Useful for setTimeout/setInterval callbacks.
|
|
335
|
+
*
|
|
336
|
+
* @param callback - Function to wrap
|
|
337
|
+
* @returns Function that no-ops if aborted
|
|
338
|
+
*/
|
|
339
|
+
safe<A extends any[]>(callback: (...args: A) => void): (...args: A) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Create a child context that aborts when this context aborts.
|
|
342
|
+
* Useful for sub-operations that should cancel with parent.
|
|
343
|
+
*/
|
|
344
|
+
fork(): AbortableContext;
|
|
345
|
+
/**
|
|
346
|
+
* Create an independent context that doesn't abort with parent.
|
|
347
|
+
* Useful for background operations that should continue.
|
|
348
|
+
*/
|
|
349
|
+
spawn(): AbortableContext;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Context passed to effect callbacks.
|
|
353
|
+
*
|
|
354
|
+
* Provides lifecycle utilities and run information.
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```ts
|
|
358
|
+
* effect((ctx) => {
|
|
359
|
+
* if (ctx.nth === 0) return; // Skip first run
|
|
360
|
+
*
|
|
361
|
+
* ctx.onError((err) => console.error(err));
|
|
362
|
+
*
|
|
363
|
+
* const interval = setInterval(tick, 1000);
|
|
364
|
+
* ctx.onCleanup(() => clearInterval(interval));
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
export interface EffectContext extends UsableContext {
|
|
369
|
+
/**
|
|
370
|
+
* How many times this effect has run.
|
|
371
|
+
* - 0 on first run
|
|
372
|
+
* - 1 on second run
|
|
373
|
+
* - etc.
|
|
374
|
+
*
|
|
375
|
+
* Useful for skipping logic on initial run:
|
|
376
|
+
* ```ts
|
|
377
|
+
* if (ctx.nth === 0) return; // Skip initialization
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
nth: number;
|
|
381
|
+
/**
|
|
382
|
+
* Effect key from options, for debugging.
|
|
383
|
+
*/
|
|
384
|
+
key: string | undefined;
|
|
385
|
+
/**
|
|
386
|
+
* Register an error handler for this effect run.
|
|
387
|
+
* If registered, errors are caught and passed to handler
|
|
388
|
+
* instead of propagating up.
|
|
389
|
+
*
|
|
390
|
+
* @param handler - Called with error if effect throws
|
|
391
|
+
*/
|
|
392
|
+
onError(handler: (error: unknown) => void): void;
|
|
393
|
+
/**
|
|
394
|
+
* Register a cleanup function to run before next effect run.
|
|
395
|
+
* Useful for cleaning up subscriptions, timers, etc.
|
|
396
|
+
*
|
|
397
|
+
* Note: Does NOT run on dispose, only before re-runs.
|
|
398
|
+
*
|
|
399
|
+
* @param cleanup - Function to call for cleanup
|
|
400
|
+
*/
|
|
401
|
+
onCleanup(cleanup: VoidFunction): void;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @deprecated ActionContext removed - handlers are now simple functions.
|
|
405
|
+
* For lifecycle features (cancellation, error handling), use abortable wrapper.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```ts
|
|
409
|
+
* // Simple action
|
|
410
|
+
* const search = action(async (query: string) => {
|
|
411
|
+
* return fetch(`/search?q=${query}`).then(r => r.json());
|
|
412
|
+
* });
|
|
413
|
+
*
|
|
414
|
+
* // With cancellation - wrap in abortable
|
|
415
|
+
* const searchAbortable = abortable(async ({ signal, abort }, query: string) => {
|
|
416
|
+
* abort(); // Cancel previous
|
|
417
|
+
* const res = await fetch(`/search?q=${query}`, { signal });
|
|
418
|
+
* return res.json();
|
|
419
|
+
* });
|
|
420
|
+
* const search = action((query: string) => searchAbortable(query));
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
export interface ActionContext {
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @deprecated OnContext removed - listeners are now simple functions.
|
|
427
|
+
* For lifecycle features, wrap listener logic in abortable.
|
|
428
|
+
*/
|
|
429
|
+
export interface OnContext {
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Action type - callable dispatcher with subscription methods.
|
|
433
|
+
*
|
|
434
|
+
* Actions are the core primitive for dispatching and handling events/commands.
|
|
435
|
+
*
|
|
436
|
+
* **Two patterns:**
|
|
437
|
+
* - `Action<T, void>` — Void action for notifications (use "on" prefix: `onClick`)
|
|
438
|
+
* - `Action<T, R>` — Action with handler that returns R (use verbs: `addToCart`)
|
|
439
|
+
*
|
|
440
|
+
* **Key features:**
|
|
441
|
+
* - Callable: `action(payload)` dispatches and returns result
|
|
442
|
+
* - Thenable: `await action` waits for next dispatch
|
|
443
|
+
* - Subscribable: `action.on(listener)` registers listeners
|
|
444
|
+
* - Sealable: `{ sealed: true }` for one-time initialization
|
|
445
|
+
*
|
|
446
|
+
* @template T - Payload type
|
|
447
|
+
* @template R - Return type (void for void actions)
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* // Void action (notification)
|
|
452
|
+
* const onClick = action<MouseEvent>();
|
|
453
|
+
* onClick.on((e) => console.log(e.clientX));
|
|
454
|
+
* onClick(event); // → void
|
|
455
|
+
*
|
|
456
|
+
* // Action with handler (command)
|
|
457
|
+
* const addToCart = action((item: Item) => {
|
|
458
|
+
* setCart([...cart(), item]);
|
|
459
|
+
* return cart().length;
|
|
460
|
+
* });
|
|
461
|
+
* const count = addToCart(item); // → number
|
|
462
|
+
*
|
|
463
|
+
* // With cancellation - wrap in abortable
|
|
464
|
+
* const searchAbortable = abortable(async ({ signal, abort }, query: string) => {
|
|
465
|
+
* abort(); // Cancel previous
|
|
466
|
+
* const res = await fetch(`/search?q=${query}`, { signal });
|
|
467
|
+
* return res.json();
|
|
468
|
+
* });
|
|
469
|
+
* const search = action((query: string) => searchAbortable(query));
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
export type Action<T, R = void> = {
|
|
473
|
+
/**
|
|
474
|
+
* Dispatch the action with payload.
|
|
475
|
+
* Executes handler (if any), notifies listeners, returns result.
|
|
476
|
+
*
|
|
477
|
+
* @param payload - Data to dispatch
|
|
478
|
+
* @returns Handler result (undefined for void actions)
|
|
479
|
+
*/
|
|
480
|
+
(payload: T): R;
|
|
481
|
+
/**
|
|
482
|
+
* Check if action is sealed (no more listener notifications).
|
|
483
|
+
* Actions with `{ sealed: true }` seal after first dispatch.
|
|
484
|
+
*/
|
|
485
|
+
sealed(): boolean;
|
|
486
|
+
/**
|
|
487
|
+
* Check if action has been dispatched at least once.
|
|
488
|
+
*/
|
|
489
|
+
fired(): boolean;
|
|
490
|
+
/**
|
|
491
|
+
* Get last dispatched payload, or wait for next dispatch.
|
|
492
|
+
* Unlike `await action` (always waits for NEXT), this returns
|
|
493
|
+
* immediately if already fired.
|
|
494
|
+
*/
|
|
495
|
+
latest(): Promise<T>;
|
|
496
|
+
/**
|
|
497
|
+
* Subscribe a listener to this action.
|
|
498
|
+
*
|
|
499
|
+
* Listener receives payload on each dispatch.
|
|
500
|
+
* For sealed actions, late subscribers fire immediately with last payload.
|
|
501
|
+
*
|
|
502
|
+
* @param listener - Called on each dispatch with payload
|
|
503
|
+
* @returns Unsubscribe function
|
|
504
|
+
*/
|
|
505
|
+
on(listener: (payload: T) => void | Promise<void>): VoidFunction;
|
|
506
|
+
/**
|
|
507
|
+
* Make action thenable (PromiseLike).
|
|
508
|
+
* Enables `await action` to wait for next dispatch.
|
|
509
|
+
*
|
|
510
|
+
* Note: Always waits for NEXT dispatch, even if already fired.
|
|
511
|
+
* Use `.latest()` to get current value if available.
|
|
512
|
+
*/
|
|
513
|
+
then<R1 = T, R2 = never>(onFulfilled?: ((value: T) => R1 | PromiseLike<R1>) | null, onRejected?: ((reason: any) => R2 | PromiseLike<R2>) | null): Promise<R1 | R2>;
|
|
514
|
+
/**
|
|
515
|
+
* Dispose the action, clearing all listeners and state.
|
|
516
|
+
* After dispose, dispatches still work but listeners don't fire.
|
|
517
|
+
*/
|
|
518
|
+
dispose(): void;
|
|
519
|
+
as<NewR extends R = R, NewT extends T = T>(): Action<NewT, NewR>;
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Result of a loadable operation - represents async state.
|
|
523
|
+
*
|
|
524
|
+
* Used by `loadable()` to extract loading/data/error from promises.
|
|
525
|
+
*
|
|
526
|
+
* @template T - The type of resolved data
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* const state = loadable(userPromise);
|
|
531
|
+
* if (state?.loading) return <Spinner />;
|
|
532
|
+
* if (state?.error) return <Error error={state.error} />;
|
|
533
|
+
* return <User data={state.data} />;
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
export type LoadableResult<T> = {
|
|
537
|
+
/** True while promise is pending */
|
|
538
|
+
loading: boolean;
|
|
539
|
+
/** Resolved value (undefined while loading or on error) */
|
|
540
|
+
data: T | undefined;
|
|
541
|
+
/** Rejection reason (undefined while loading or on success) */
|
|
542
|
+
error: unknown | undefined;
|
|
543
|
+
};
|
|
544
|
+
/**
|
|
545
|
+
* Extracts the resolved type from a Promise type.
|
|
546
|
+
* `PromiseValue<Promise<string>>` → `string`
|
|
547
|
+
*/
|
|
548
|
+
export type PromiseValue<T> = T extends Promise<infer U> ? U : never;
|
|
549
|
+
/**
|
|
550
|
+
* Type utility to check if T includes null or undefined.
|
|
551
|
+
* Used for conditional return types in loadable().
|
|
552
|
+
*/
|
|
553
|
+
export type IncludesNullish<T> = null extends T ? true : undefined extends T ? true : false;
|
|
554
|
+
/**
|
|
555
|
+
* Return type of loadable() - accounts for nullish signal values.
|
|
556
|
+
* If signal can be null/undefined, return type includes null.
|
|
557
|
+
*/
|
|
558
|
+
export type LoadableReturn<TValue> = IncludesNullish<TValue> extends true ? LoadableResult<PromiseValue<NonNullable<TValue>>> | null : LoadableResult<PromiseValue<TValue>>;
|
|
559
|
+
/**
|
|
560
|
+
* Simple listener callback type.
|
|
561
|
+
* @template T - Value type passed to listener
|
|
562
|
+
*/
|
|
563
|
+
export type Listener<T> = (value: T) => void;
|
|
564
|
+
/**
|
|
565
|
+
* Flexible listener specification for emitter.
|
|
566
|
+
* Can be:
|
|
567
|
+
* - Single listener function
|
|
568
|
+
* - Array of listener functions
|
|
569
|
+
* - Factory function returning listener(s)
|
|
570
|
+
*
|
|
571
|
+
* @template T - Value type passed to listeners
|
|
572
|
+
*/
|
|
573
|
+
export type SingleOrMultipleListeners<T> = Listener<T> | Listener<T>[] | ((value: T) => Listener<T> | Listener<T>[] | undefined);
|
|
574
|
+
/**
|
|
575
|
+
* Built-in equality strategy names.
|
|
576
|
+
*
|
|
577
|
+
* Used with atoms to control when subscribers are notified:
|
|
578
|
+
* - `"strict"` - Object.is (default, fastest)
|
|
579
|
+
* - `"shallow"` - Compare object keys/array items with Object.is
|
|
580
|
+
* - `"shallow2"` - 2 levels deep
|
|
581
|
+
* - `"shallow3"` - 3 levels deep
|
|
582
|
+
* - `"deep"` - Full recursive comparison (slowest)
|
|
583
|
+
*/
|
|
584
|
+
export type EqualityShorthand = "strict" | "shallow" | "shallow2" | "shallow3" | "deep";
|
|
585
|
+
/**
|
|
586
|
+
* Equality strategy for change detection.
|
|
587
|
+
*
|
|
588
|
+
* Can be a shorthand string or custom comparison function.
|
|
589
|
+
* Used by atoms to determine if value has "changed" -
|
|
590
|
+
* if equal, subscribers won't be notified.
|
|
591
|
+
*
|
|
592
|
+
* @template T - Type of values being compared
|
|
593
|
+
*
|
|
594
|
+
* @example
|
|
595
|
+
* ```ts
|
|
596
|
+
* // Using shorthand
|
|
597
|
+
* const [user, setUser] = atom(data, { equals: "shallow" });
|
|
598
|
+
*
|
|
599
|
+
* // Using custom function
|
|
600
|
+
* const [user, setUser] = atom(data, {
|
|
601
|
+
* equals: (a, b) => a.id === b.id
|
|
602
|
+
* });
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
export type Equality<T = unknown> = EqualityShorthand | ((a: T, b: T) => boolean);
|
|
606
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,IAAI;IAC5B;;;;OAIG;IACH,IAAI,CAAC,CAAC;IAEN;;;;OAIG;IACH,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,YAAY,CAAC;CAChD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,IAAI,CACvE,MAAM,EAAE,CAAC,KACN,CAAC,CAAC;AAEP;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,EAAE,C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AC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,IACnC,QAAQ,CAAC,CAAC,CAAC,GACX,QAAQ,CAAC,CAAC,CAAC,EAAE,GACb,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC;AAM5D;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,SAAS,GACT,UAAU,GACV,UAAU,GACV,MAAM,CAAC;AAEX;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,IAC5B,iBAAiB,GACjB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,aAAa;AACb,+EAA+E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads reactive values without creating dependencies.
|
|
3
|
+
*
|
|
4
|
+
* @param fn - Function that reads reactive values
|
|
5
|
+
* @returns The return value of the function
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* effect(() => {
|
|
9
|
+
* const a = count(); // tracked
|
|
10
|
+
* const b = untrack(() => name()); // not tracked
|
|
11
|
+
* });
|
|
12
|
+
*/
|
|
13
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
14
|
+
//# sourceMappingURL=untrack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"untrack.d.ts","sourceRoot":"","sources":["../src/untrack.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEzC"}
|
package/dist/untrack.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { withHooks } from "./hooks";
|
|
2
|
+
/**
|
|
3
|
+
* Reads reactive values without creating dependencies.
|
|
4
|
+
*
|
|
5
|
+
* @param fn - Function that reads reactive values
|
|
6
|
+
* @returns The return value of the function
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* effect(() => {
|
|
10
|
+
* const a = count(); // tracked
|
|
11
|
+
* const b = untrack(() => name()); // not tracked
|
|
12
|
+
* });
|
|
13
|
+
*/
|
|
14
|
+
export function untrack(fn) {
|
|
15
|
+
return withHooks({ track: undefined }, fn);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=untrack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"untrack.js","sourceRoot":"","sources":["../src/untrack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAI,EAAW;IACpC,OAAO,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Signal, Setter, WithUse } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a mappable tuple by adding .use() method to the tuple.
|
|
4
|
+
* The tuple can still be destructured normally: const [signal, setter] = withUse([s, set])
|
|
5
|
+
*
|
|
6
|
+
* @param tuple - The tuple [Signal, Setter] to make mappable
|
|
7
|
+
* @returns The same tuple with .use() method attached
|
|
8
|
+
*/
|
|
9
|
+
export declare function withUse<T extends readonly [Signal<any>, Setter<any>]>(tuple: T): WithUse<T>;
|
|
10
|
+
//# sourceMappingURL=withUse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withUse.d.ts","sourceRoot":"","sources":["../../src/utils/withUse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EACnE,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|