storion 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +771 -561
- package/dist/async/async.d.ts +87 -0
- package/dist/async/async.d.ts.map +1 -0
- package/dist/async/index.d.ts +13 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +451 -0
- package/dist/async/types.d.ts +275 -0
- package/dist/async/types.d.ts.map +1 -0
- package/dist/collection.d.ts +42 -0
- package/dist/collection.d.ts.map +1 -0
- package/dist/core/container.d.ts +33 -2
- package/dist/core/container.d.ts.map +1 -1
- package/dist/core/createResolver.d.ts +47 -0
- package/dist/core/createResolver.d.ts.map +1 -0
- package/dist/core/effect.d.ts.map +1 -1
- package/dist/core/equality.d.ts +23 -3
- package/dist/core/equality.d.ts.map +1 -1
- package/dist/core/fnWrapper.d.ts +54 -0
- package/dist/core/fnWrapper.d.ts.map +1 -0
- package/dist/core/middleware.d.ts +10 -10
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/pick.d.ts +6 -6
- package/dist/core/pick.d.ts.map +1 -1
- package/dist/core/store.d.ts +8 -8
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/storeContext.d.ts +63 -0
- package/dist/core/storeContext.d.ts.map +1 -0
- package/dist/devtools/controller.d.ts +4 -0
- package/dist/devtools/controller.d.ts.map +1 -0
- package/dist/devtools/index.d.ts +16 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +239 -0
- package/dist/devtools/middleware.d.ts +22 -0
- package/dist/devtools/middleware.d.ts.map +1 -0
- package/dist/devtools/types.d.ts +116 -0
- package/dist/devtools/types.d.ts.map +1 -0
- package/dist/devtools-panel/DevtoolsPanel.d.ts +17 -0
- package/dist/devtools-panel/DevtoolsPanel.d.ts.map +1 -0
- package/dist/devtools-panel/components/CompareModal.d.ts +10 -0
- package/dist/devtools-panel/components/CompareModal.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventEntry.d.ts +14 -0
- package/dist/devtools-panel/components/EventEntry.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventFilterBar.d.ts +10 -0
- package/dist/devtools-panel/components/EventFilterBar.d.ts.map +1 -0
- package/dist/devtools-panel/components/EventsTab.d.ts +15 -0
- package/dist/devtools-panel/components/EventsTab.d.ts.map +1 -0
- package/dist/devtools-panel/components/ResizeHandle.d.ts +8 -0
- package/dist/devtools-panel/components/ResizeHandle.d.ts.map +1 -0
- package/dist/devtools-panel/components/StoreEntry.d.ts +13 -0
- package/dist/devtools-panel/components/StoreEntry.d.ts.map +1 -0
- package/dist/devtools-panel/components/StoresTab.d.ts +12 -0
- package/dist/devtools-panel/components/StoresTab.d.ts.map +1 -0
- package/dist/devtools-panel/components/TabLayout.d.ts +48 -0
- package/dist/devtools-panel/components/TabLayout.d.ts.map +1 -0
- package/dist/devtools-panel/components/icons.d.ts +27 -0
- package/dist/devtools-panel/components/icons.d.ts.map +1 -0
- package/dist/devtools-panel/components/index.d.ts +15 -0
- package/dist/devtools-panel/components/index.d.ts.map +1 -0
- package/dist/devtools-panel/hooks.d.ts +23 -0
- package/dist/devtools-panel/hooks.d.ts.map +1 -0
- package/dist/devtools-panel/index.d.ts +25 -0
- package/dist/devtools-panel/index.d.ts.map +1 -0
- package/dist/devtools-panel/index.js +3326 -0
- package/dist/devtools-panel/mount.d.ts +41 -0
- package/dist/devtools-panel/mount.d.ts.map +1 -0
- package/dist/devtools-panel/styles.d.ts +50 -0
- package/dist/devtools-panel/styles.d.ts.map +1 -0
- package/dist/devtools-panel/types.d.ts +15 -0
- package/dist/devtools-panel/types.d.ts.map +1 -0
- package/dist/devtools-panel/utils.d.ts +21 -0
- package/dist/devtools-panel/utils.d.ts.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/is.d.ts +69 -0
- package/dist/is.d.ts.map +1 -0
- package/dist/react/create.d.ts +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +210 -34
- package/dist/react/useLocalStore.d.ts.map +1 -1
- package/dist/react/useStore.d.ts +2 -2
- package/dist/react/useStore.d.ts.map +1 -1
- package/dist/react/withStore.d.ts +140 -0
- package/dist/react/withStore.d.ts.map +1 -0
- package/dist/{index-rLf6DusB.js → store-Yv-9gPVf.js} +543 -742
- package/dist/storion.js +809 -9
- package/dist/trigger.d.ts +40 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/types.d.ts +538 -71
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async data mode:
|
|
3
|
+
* - "fresh": data is undefined during loading/error (only show fresh data)
|
|
4
|
+
* - "stale": data is preserved during loading/error (stale-while-revalidate)
|
|
5
|
+
*/
|
|
6
|
+
export type AsyncMode = "fresh" | "stale";
|
|
7
|
+
export type AsyncStatus = "idle" | "pending" | "success" | "error";
|
|
8
|
+
/**
|
|
9
|
+
* Serialized async state for persistence/hydration.
|
|
10
|
+
* Only success states are persisted.
|
|
11
|
+
*/
|
|
12
|
+
export type SerializedAsyncState<T = unknown> = {
|
|
13
|
+
status: "success";
|
|
14
|
+
mode: AsyncMode;
|
|
15
|
+
data: T;
|
|
16
|
+
} | null;
|
|
17
|
+
/**
|
|
18
|
+
* Async state with mode support.
|
|
19
|
+
* - Fresh mode: data is undefined during idle/pending/error
|
|
20
|
+
* - Stale mode: data is preserved (T) during pending/error after first load
|
|
21
|
+
*/
|
|
22
|
+
export type AsyncState<T = unknown, M extends AsyncMode = AsyncMode> = AsyncIdleState<T, M> | AsyncPendingState<T, M> | AsyncSuccessState<T> | AsyncErrorState<T, M>;
|
|
23
|
+
export interface AsyncIdleStateFresh {
|
|
24
|
+
status: "idle";
|
|
25
|
+
mode: "fresh";
|
|
26
|
+
data: undefined;
|
|
27
|
+
error: undefined;
|
|
28
|
+
timestamp: undefined;
|
|
29
|
+
/** @internal Request ID for concurrency control */
|
|
30
|
+
__requestId?: AsyncRequestId;
|
|
31
|
+
toJSON?(): SerializedAsyncState<undefined>;
|
|
32
|
+
}
|
|
33
|
+
export interface AsyncPendingStateFresh<T = unknown> {
|
|
34
|
+
status: "pending";
|
|
35
|
+
mode: "fresh";
|
|
36
|
+
data: undefined;
|
|
37
|
+
error: undefined;
|
|
38
|
+
timestamp: undefined;
|
|
39
|
+
/** @internal Key for Suspense promise tracking */
|
|
40
|
+
__key?: AsyncKey<T>;
|
|
41
|
+
/** @internal Request ID for concurrency control */
|
|
42
|
+
__requestId?: AsyncRequestId;
|
|
43
|
+
toJSON?(): SerializedAsyncState<T>;
|
|
44
|
+
}
|
|
45
|
+
export interface AsyncErrorStateFresh {
|
|
46
|
+
status: "error";
|
|
47
|
+
mode: "fresh";
|
|
48
|
+
data: undefined;
|
|
49
|
+
error: Error;
|
|
50
|
+
timestamp: undefined;
|
|
51
|
+
/** @internal Request ID for concurrency control */
|
|
52
|
+
__requestId?: AsyncRequestId;
|
|
53
|
+
toJSON?(): SerializedAsyncState<undefined>;
|
|
54
|
+
}
|
|
55
|
+
export interface AsyncIdleStateStale<T = unknown> {
|
|
56
|
+
status: "idle";
|
|
57
|
+
mode: "stale";
|
|
58
|
+
data: T;
|
|
59
|
+
error: undefined;
|
|
60
|
+
timestamp: undefined;
|
|
61
|
+
/** @internal Request ID for concurrency control */
|
|
62
|
+
__requestId?: AsyncRequestId;
|
|
63
|
+
toJSON?(): SerializedAsyncState<T>;
|
|
64
|
+
}
|
|
65
|
+
export interface AsyncPendingStateStale<T = unknown> {
|
|
66
|
+
status: "pending";
|
|
67
|
+
mode: "stale";
|
|
68
|
+
data: T;
|
|
69
|
+
error: undefined;
|
|
70
|
+
timestamp: undefined;
|
|
71
|
+
/** @internal Key for Suspense promise tracking */
|
|
72
|
+
__key?: AsyncKey<T>;
|
|
73
|
+
/** @internal Request ID for concurrency control */
|
|
74
|
+
__requestId?: AsyncRequestId;
|
|
75
|
+
toJSON?(): SerializedAsyncState<T>;
|
|
76
|
+
}
|
|
77
|
+
export interface AsyncErrorStateStale<T = unknown> {
|
|
78
|
+
status: "error";
|
|
79
|
+
mode: "stale";
|
|
80
|
+
data: T;
|
|
81
|
+
error: Error;
|
|
82
|
+
timestamp: undefined;
|
|
83
|
+
/** @internal Request ID for concurrency control */
|
|
84
|
+
__requestId?: AsyncRequestId;
|
|
85
|
+
toJSON?(): SerializedAsyncState<T>;
|
|
86
|
+
}
|
|
87
|
+
export type AsyncIdleState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncIdleStateFresh : M extends "stale" ? AsyncIdleStateStale<T> : AsyncIdleStateFresh | AsyncIdleStateStale<T>;
|
|
88
|
+
export type AsyncPendingState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncPendingStateFresh<T> : M extends "stale" ? AsyncPendingStateStale<T> : AsyncPendingStateFresh<T> | AsyncPendingStateStale<T>;
|
|
89
|
+
export interface AsyncSuccessState<T = unknown> {
|
|
90
|
+
status: "success";
|
|
91
|
+
mode: "fresh" | "stale";
|
|
92
|
+
data: T;
|
|
93
|
+
error: undefined;
|
|
94
|
+
timestamp: number;
|
|
95
|
+
/** @internal Request ID for concurrency control */
|
|
96
|
+
__requestId?: AsyncRequestId;
|
|
97
|
+
toJSON?(): SerializedAsyncState<T>;
|
|
98
|
+
}
|
|
99
|
+
export type AsyncErrorState<T = unknown, M extends AsyncMode = AsyncMode> = M extends "fresh" ? AsyncErrorStateFresh : M extends "stale" ? AsyncErrorStateStale<T> : AsyncErrorStateFresh | AsyncErrorStateStale<T>;
|
|
100
|
+
/**
|
|
101
|
+
* Opaque key type for linking state to pending promise.
|
|
102
|
+
* Used internally for React Suspense support.
|
|
103
|
+
*/
|
|
104
|
+
export type AsyncKey<T = unknown> = object & {
|
|
105
|
+
__brand?: T;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Request ID for detecting external state modifications.
|
|
109
|
+
* Used to prevent stale async updates from overwriting rolled-back state.
|
|
110
|
+
*/
|
|
111
|
+
export type AsyncRequestId = object;
|
|
112
|
+
/**
|
|
113
|
+
* Context passed to async handlers.
|
|
114
|
+
*/
|
|
115
|
+
export interface AsyncContext {
|
|
116
|
+
/** AbortSignal for cancellation */
|
|
117
|
+
signal: AbortSignal;
|
|
118
|
+
/**
|
|
119
|
+
* Wrap a promise to never resolve if the async operation is cancelled.
|
|
120
|
+
* Useful for nested async operations that should be cancelled together.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* async(focus, async (ctx) => {
|
|
124
|
+
* const data1 = await ctx.safe(fetch('/api/1'));
|
|
125
|
+
* const data2 = await ctx.safe(fetch('/api/2'));
|
|
126
|
+
* return { data1, data2 };
|
|
127
|
+
* });
|
|
128
|
+
*/
|
|
129
|
+
safe<T>(promise: Promise<T>): Promise<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Wrap a callback to not run if the async operation is cancelled.
|
|
132
|
+
* Useful for event handlers and timeouts.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* async(focus, async (ctx) => {
|
|
136
|
+
* setTimeout(ctx.safe(() => {
|
|
137
|
+
* // Only runs if not cancelled
|
|
138
|
+
* doSomething();
|
|
139
|
+
* }), 1000);
|
|
140
|
+
* });
|
|
141
|
+
*/
|
|
142
|
+
safe<TArgs extends unknown[], TReturn>(callback: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Cancel the current async operation.
|
|
145
|
+
* Useful for implementing timeouts.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* async(focus, async (ctx) => {
|
|
149
|
+
* // Timeout after 5 seconds
|
|
150
|
+
* setTimeout(ctx.cancel, 5000);
|
|
151
|
+
*
|
|
152
|
+
* const data = await ctx.safe(fetch('/api/slow'));
|
|
153
|
+
* return data;
|
|
154
|
+
* });
|
|
155
|
+
*/
|
|
156
|
+
cancel(): void;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Async handler function signature.
|
|
160
|
+
* Receives AsyncContext as first arg, then user-defined args.
|
|
161
|
+
*/
|
|
162
|
+
export type AsyncHandler<T, TArgs extends any[]> = (context: AsyncContext, ...args: TArgs) => T | PromiseLike<T>;
|
|
163
|
+
export interface AsyncRetryOptions {
|
|
164
|
+
/** Number of retry attempts */
|
|
165
|
+
count: number;
|
|
166
|
+
/** Delay between retries (ms) or function returning delay */
|
|
167
|
+
delay?: number | ((attempt: number, error: Error) => number);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Options for async mixin setup.
|
|
171
|
+
*/
|
|
172
|
+
export interface AsyncOptions {
|
|
173
|
+
/** Error callback */
|
|
174
|
+
onError?: (error: Error) => void;
|
|
175
|
+
/** Retry configuration */
|
|
176
|
+
retry?: number | AsyncRetryOptions;
|
|
177
|
+
/** Auto-cancel previous request on new dispatch (default: true) */
|
|
178
|
+
autoCancel?: boolean;
|
|
179
|
+
}
|
|
180
|
+
export type CancellablePromise<T> = Promise<T> & {
|
|
181
|
+
cancel(): void;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Last invocation info for async action (for typing asyncAction.last())
|
|
185
|
+
*/
|
|
186
|
+
export interface AsyncLastInvocation<T, M extends AsyncMode, TArgs extends any[]> {
|
|
187
|
+
/** Arguments passed to the last dispatch */
|
|
188
|
+
readonly args: TArgs;
|
|
189
|
+
/** Invocation count (1-indexed) */
|
|
190
|
+
readonly nth: number;
|
|
191
|
+
/** Current async state (reactive) */
|
|
192
|
+
readonly state: AsyncState<T, M>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* API returned from async() mixin.
|
|
196
|
+
*/
|
|
197
|
+
export interface AsyncActions<T, M extends AsyncMode, TArgs extends any[]> {
|
|
198
|
+
/** Dispatch the async operation */
|
|
199
|
+
dispatch(...args: TArgs): CancellablePromise<T>;
|
|
200
|
+
/** Re-dispatch with last args. Returns undefined if no previous dispatch. */
|
|
201
|
+
refresh(): CancellablePromise<T> | undefined;
|
|
202
|
+
/** Cancel ongoing operation */
|
|
203
|
+
cancel(): void;
|
|
204
|
+
/** Reset to idle state */
|
|
205
|
+
reset(): void;
|
|
206
|
+
/**
|
|
207
|
+
* Get the last invocation info including current async state.
|
|
208
|
+
* Reactive - reads from the async state, triggers re-render when state changes.
|
|
209
|
+
*
|
|
210
|
+
* @returns Last invocation info with state, or undefined if never dispatched
|
|
211
|
+
*/
|
|
212
|
+
last(): AsyncLastInvocation<T, M, TArgs> | undefined;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Infer the data type from an AsyncState
|
|
216
|
+
*/
|
|
217
|
+
export type InferAsyncData<T> = T extends AsyncState<infer D, any> ? D : never;
|
|
218
|
+
/**
|
|
219
|
+
* Infer the mode from an AsyncState
|
|
220
|
+
*/
|
|
221
|
+
export type InferAsyncMode<T> = T extends AsyncState<any, infer M> ? M : never;
|
|
222
|
+
/**
|
|
223
|
+
* Settled result for a single async state
|
|
224
|
+
*/
|
|
225
|
+
export type SettledResult<T, M extends AsyncMode = AsyncMode> = {
|
|
226
|
+
status: "success";
|
|
227
|
+
data: T;
|
|
228
|
+
} | (M extends "stale" ? {
|
|
229
|
+
status: "error";
|
|
230
|
+
error: Error;
|
|
231
|
+
data: T;
|
|
232
|
+
} : {
|
|
233
|
+
status: "error";
|
|
234
|
+
error: Error;
|
|
235
|
+
data: undefined;
|
|
236
|
+
}) | (M extends "stale" ? {
|
|
237
|
+
status: "pending";
|
|
238
|
+
data: T;
|
|
239
|
+
} : {
|
|
240
|
+
status: "pending";
|
|
241
|
+
data: undefined;
|
|
242
|
+
}) | (M extends "stale" ? {
|
|
243
|
+
status: "idle";
|
|
244
|
+
data: T;
|
|
245
|
+
} : {
|
|
246
|
+
status: "idle";
|
|
247
|
+
data: undefined;
|
|
248
|
+
});
|
|
249
|
+
/**
|
|
250
|
+
* Map a tuple of AsyncState to their data types
|
|
251
|
+
*/
|
|
252
|
+
export type MapAsyncData<T extends readonly AsyncState<any, any>[]> = {
|
|
253
|
+
-readonly [K in keyof T]: InferAsyncData<T[K]>;
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Map a tuple of AsyncState to SettledResult
|
|
257
|
+
*/
|
|
258
|
+
export type MapSettledResult<T extends readonly AsyncState<any, any>[]> = {
|
|
259
|
+
-readonly [K in keyof T]: SettledResult<InferAsyncData<T[K]>, InferAsyncMode<T[K]>>;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Race result type - tuple of [key, value]
|
|
263
|
+
*/
|
|
264
|
+
export type RaceResult<T extends Record<string, AsyncState<any, any>>> = {
|
|
265
|
+
[K in keyof T]: [K, InferAsyncData<T[K]>];
|
|
266
|
+
}[keyof T];
|
|
267
|
+
export declare class AsyncNotReadyError extends Error {
|
|
268
|
+
readonly status: AsyncStatus;
|
|
269
|
+
constructor(message: string, status: AsyncStatus);
|
|
270
|
+
}
|
|
271
|
+
export declare class AsyncAggregateError extends Error {
|
|
272
|
+
readonly errors: Error[];
|
|
273
|
+
constructor(message: string, errors: Error[]);
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/async/types.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAI1C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC9C,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,IAAI,CAAC;AAET;;;;GAIG;AACH,MAAM,MAAM,UAAU,CAAC,C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,SAAQ,KAAK;aACC,MAAM,EAAE,KAAK,EAAE;gBAAhD,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,KAAK,EAAE;CAI7D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy-instantiation Map wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Creates items on first access via `get()`. Useful for managing
|
|
5
|
+
* collections where items should be created on-demand.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Create a collection of emitters, one per property key
|
|
10
|
+
* const emitters = collection((key: string) => emitter<void>());
|
|
11
|
+
*
|
|
12
|
+
* // First access creates the emitter
|
|
13
|
+
* const countEmitter = emitters.get("count"); // creates new emitter
|
|
14
|
+
* const countEmitter2 = emitters.get("count"); // returns same emitter
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param createItem - Factory function to create new items
|
|
18
|
+
* @param initialItems - Optional initial entries
|
|
19
|
+
* @returns A Map-like object with lazy instantiation on `get()`
|
|
20
|
+
*/
|
|
21
|
+
export declare function collection<TKey, TValue>(createItem: (key: TKey) => TValue, initialItems?: readonly [TKey, TValue][]): {
|
|
22
|
+
with(key: TKey, callback: (item: TValue) => void): /*elided*/ any;
|
|
23
|
+
/** Check if key exists (does NOT create item) */
|
|
24
|
+
has(key: TKey): boolean;
|
|
25
|
+
/** Get item by key, creating it if it doesn't exist */
|
|
26
|
+
get(key: TKey): NonNullable<TValue>;
|
|
27
|
+
/** Explicitly set an item */
|
|
28
|
+
set(key: TKey, value: TValue): /*elided*/ any;
|
|
29
|
+
/** Number of items in the collection */
|
|
30
|
+
readonly size: number;
|
|
31
|
+
/** Remove all items */
|
|
32
|
+
clear(): /*elided*/ any;
|
|
33
|
+
/** Remove a specific item */
|
|
34
|
+
delete(key: TKey): /*elided*/ any;
|
|
35
|
+
/** Iterate over keys */
|
|
36
|
+
keys(): MapIterator<TKey>;
|
|
37
|
+
/** Iterate over values */
|
|
38
|
+
values(): MapIterator<TValue>;
|
|
39
|
+
/** Iterate over [key, value] pairs */
|
|
40
|
+
entries(): MapIterator<[TKey, TValue]>;
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,MAAM,EACjC,YAAY,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;cAK5B,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IAOhD,iDAAiD;aACxC,IAAI;IAIb,uDAAuD;aAC9C,IAAI;IAOb,6BAA6B;aACpB,IAAI,SAAS,MAAM;IAK5B,wCAAwC;;IAKxC,uBAAuB;;IAMvB,6BAA6B;gBACjB,IAAI;IAKhB,wBAAwB;;IAKxB,0BAA0B;;IAK1B,sCAAsC;;EAKzC"}
|
package/dist/core/container.d.ts
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
|
-
import { StoreContainer, ContainerOptions } from '../types';
|
|
1
|
+
import { StoreContainer, ContainerOptions, StoreMiddleware } from '../types';
|
|
2
2
|
|
|
3
|
+
interface DefaultMiddlewareConfig {
|
|
4
|
+
/** Middleware to run before container's middleware */
|
|
5
|
+
pre?: StoreMiddleware[];
|
|
6
|
+
/** Middleware to run after container's middleware */
|
|
7
|
+
post?: StoreMiddleware[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Container function with static defaults method.
|
|
11
|
+
*/
|
|
12
|
+
interface ContainerFn {
|
|
13
|
+
(options?: ContainerOptions): StoreContainer;
|
|
14
|
+
/**
|
|
15
|
+
* Add default middleware that will be applied to all new containers.
|
|
16
|
+
*/
|
|
17
|
+
defaults: {
|
|
18
|
+
(config?: DefaultMiddlewareConfig): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
3
22
|
/**
|
|
4
23
|
* Create a store container.
|
|
24
|
+
*
|
|
25
|
+
* Container provides resolver methods plus store-specific lifecycle:
|
|
26
|
+
* - get(spec): cached instance
|
|
27
|
+
* - create(spec): fresh instance
|
|
28
|
+
* - set(spec, override): override for DI/testing
|
|
29
|
+
* - has(spec): check cache
|
|
30
|
+
* - tryGet(spec): get if cached
|
|
31
|
+
* - delete(spec): remove from cache
|
|
32
|
+
* - clear(): dispose all
|
|
33
|
+
* - scope(): child container
|
|
34
|
+
* - onCreate/onDispose: lifecycle events
|
|
5
35
|
*/
|
|
6
|
-
export declare
|
|
36
|
+
export declare const container: ContainerFn;
|
|
37
|
+
export {};
|
|
7
38
|
//# sourceMappingURL=container.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/core/container.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAIrB,MAAM,UAAU,CAAC;AAUlB,UAAU,uBAAuB;IAC/B,sDAAsD;IACtD,GAAG,CAAC,EAAE,eAAe,EAAE,CAAC;IACxB,qDAAqD;IACrD,IAAI,CAAC,EAAE,eAAe,EAAE,CAAC;CAC1B;AAYD;;GAEG;AACH,UAAU,WAAW;IACnB,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC;IAC7C;;OAEG;IACH,QAAQ,EAAE;QACR,CAAC,MAAM,CAAC,EAAE,uBAAuB,GAAG,IAAI,CAAC;QACzC,KAAK,IAAI,IAAI,CAAC;KACf,CAAC;CACH;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,EAAE,WA4TvB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Factory, Middleware, Resolver, ResolverOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
export type { Factory, Middleware, MiddlewareContext, Resolver, ResolverOptions, } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new resolver with optional middleware and parent.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createResolver(options?: ResolverOptions): Resolver;
|
|
8
|
+
/**
|
|
9
|
+
* Create a middleware that only applies to factories matching a predicate.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const storeOnlyMiddleware = when(
|
|
14
|
+
* (factory) => is(factory, "store.spec"),
|
|
15
|
+
* (ctx) => {
|
|
16
|
+
* console.log("Creating store:", ctx.factory.name);
|
|
17
|
+
* return ctx.next();
|
|
18
|
+
* }
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function when(predicate: (factory: Factory) => boolean, middleware: Middleware): Middleware;
|
|
23
|
+
/**
|
|
24
|
+
* Create a logging middleware for debugging.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const app = createResolver({
|
|
29
|
+
* middleware: [createLoggingMiddleware("App")],
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createLoggingMiddleware(prefix?: string): Middleware;
|
|
34
|
+
/**
|
|
35
|
+
* Create a middleware that validates factory results.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const validateMiddleware = createValidationMiddleware((result) => {
|
|
40
|
+
* if (result === null || result === undefined) {
|
|
41
|
+
* throw new Error("Factory returned null/undefined");
|
|
42
|
+
* }
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function createValidationMiddleware(validate: (result: unknown, factory: Factory) => void): Middleware;
|
|
47
|
+
//# sourceMappingURL=createResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createResolver.d.ts","sourceRoot":"","sources":["../../src/core/createResolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,QAAQ,EACR,eAAe,EAEhB,MAAM,UAAU,CAAC;AAIlB,YAAY,EACV,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,QAAQ,EACR,eAAe,GAChB,MAAM,UAAU,CAAC;AAmClB;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAoItE;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAClB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,EACxC,UAAU,EAAE,UAAU,GACrB,UAAU,CAOZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,SAAa,GAAG,UAAU,CAUvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GACpD,UAAU,CAMZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/core/effect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"effect.d.ts","sourceRoot":"","sources":["../../src/core/effect.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,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,EAAE,aAAa,KAAK,IAAI,CAAC;AAsBpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CA4R1E"}
|
package/dist/core/equality.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Equality } from '../types';
|
|
1
|
+
import { Equality, EqualityShorthand } from '../types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Strict equality (Object.is).
|
|
@@ -6,8 +6,27 @@ import { Equality } from '../types';
|
|
|
6
6
|
export declare function strictEqual<T>(a: T, b: T): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Shallow equality for objects/arrays.
|
|
9
|
+
* Compares by reference for each top-level key/index.
|
|
10
|
+
*
|
|
11
|
+
* @param itemEqual - Optional comparator for each item/value (defaults to Object.is)
|
|
9
12
|
*/
|
|
10
|
-
export declare function shallowEqual<T>(a: T, b: T): boolean;
|
|
13
|
+
export declare function shallowEqual<T>(a: T, b: T, itemEqual?: (a: unknown, b: unknown) => boolean): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 2-level shallow equality.
|
|
16
|
+
* Compares keys/length, then shallow compares each item/value.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* [{ id: 1, data: obj }] vs [{ id: 1, data: obj }] // true (same obj ref)
|
|
20
|
+
*/
|
|
21
|
+
export declare function shallow2Equal<T>(a: T, b: T): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 3-level shallow equality.
|
|
24
|
+
* Compares keys/length, then shallow2 compares each item/value.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* [{ id: 1, nested: { data: obj } }] vs [{ id: 1, nested: { data: obj } }] // true
|
|
28
|
+
*/
|
|
29
|
+
export declare function shallow3Equal<T>(a: T, b: T): boolean;
|
|
11
30
|
/**
|
|
12
31
|
* Deep equality.
|
|
13
32
|
*/
|
|
@@ -15,5 +34,6 @@ export declare const deepEqual: (value: any, other: any) => boolean;
|
|
|
15
34
|
/**
|
|
16
35
|
* Resolve equality strategy to a function.
|
|
17
36
|
*/
|
|
18
|
-
export declare function resolveEquality<T>(
|
|
37
|
+
export declare function resolveEquality<T>(e: Equality<T> | undefined): (a: T, b: T) => boolean;
|
|
38
|
+
export declare function equality(shorthand: EqualityShorthand): (a: unknown, b: unknown) => boolean;
|
|
19
39
|
//# sourceMappingURL=equality.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/core/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/core/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG5D;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,EACJ,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAmB,GACzD,OAAO,CAgBT;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAEpD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,qCAAU,CAAC;AAEjC;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,GACzB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAOzB;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,iBAAiB,+BATlC,OAAO,CAWzB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for wrapping functions while preserving original references.
|
|
3
|
+
*
|
|
4
|
+
* This allows wrapped and original functions to be treated as the same
|
|
5
|
+
* for deduplication purposes (e.g., in trigger()).
|
|
6
|
+
*/
|
|
7
|
+
/** Symbol to mark the original function on wrapped functions */
|
|
8
|
+
export declare const ORIGINAL_FN: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a function while marking the original for later retrieval.
|
|
11
|
+
*
|
|
12
|
+
* @param originalFn - The original function to wrap
|
|
13
|
+
* @param createWrapper - Factory function that receives the original and returns the wrapper
|
|
14
|
+
* @returns The wrapper function with the original marked
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const original = (x: number) => x * 2;
|
|
19
|
+
* const wrapped = wrapFn(original, (fn) => {
|
|
20
|
+
* return (x: number) => {
|
|
21
|
+
* console.log('calling...');
|
|
22
|
+
* return fn(x);
|
|
23
|
+
* };
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* unwrapFn(wrapped) === original; // true
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function wrapFn<T extends Function>(originalFn: T, createWrapper: (original: T) => T): T;
|
|
30
|
+
/**
|
|
31
|
+
* Unwrap a function to get its original reference.
|
|
32
|
+
* If the function is not wrapped, returns the function itself.
|
|
33
|
+
*
|
|
34
|
+
* @param fn - The function to unwrap
|
|
35
|
+
* @returns The original function or the function itself if not wrapped
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const original = (x: number) => x * 2;
|
|
40
|
+
* const wrapped = wrapFn(original, (...args) => original(...args));
|
|
41
|
+
*
|
|
42
|
+
* unwrapFn(wrapped) === original; // true
|
|
43
|
+
* unwrapFn(original) === original; // true
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function unwrapFn<T extends Function>(fn: T): T;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a function is wrapped.
|
|
49
|
+
*
|
|
50
|
+
* @param fn - The function to check
|
|
51
|
+
* @returns true if the function has an original reference marked
|
|
52
|
+
*/
|
|
53
|
+
export declare function isWrappedFn(fn: Function): boolean;
|
|
54
|
+
//# sourceMappingURL=fnWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fnWrapper.d.ts","sourceRoot":"","sources":["../../src/core/fnWrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gEAAgE;AAChE,eAAO,MAAM,WAAW,eAAmC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,QAAQ,EACvC,UAAU,EAAE,CAAC,EACb,aAAa,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAChC,CAAC,CAIH;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAGrD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAEjD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StoreMiddleware, StoreMiddlewareContext } from '../types';
|
|
2
2
|
|
|
3
|
-
/** Pattern type for matching
|
|
3
|
+
/** Pattern type for matching displayName */
|
|
4
4
|
export type SpecPattern = string | RegExp;
|
|
5
5
|
/**
|
|
6
|
-
* Compose multiple middleware into one.
|
|
6
|
+
* Compose multiple store middleware into one.
|
|
7
7
|
* Middleware are applied in order (first middleware wraps the chain).
|
|
8
8
|
*/
|
|
9
9
|
export declare function compose(...middlewares: StoreMiddleware[]): StoreMiddleware;
|
|
@@ -11,11 +11,11 @@ export declare function compose(...middlewares: StoreMiddleware[]): StoreMiddlew
|
|
|
11
11
|
* Conditionally apply middleware based on a predicate or pattern(s).
|
|
12
12
|
*
|
|
13
13
|
* @overload Apply middleware when predicate returns true
|
|
14
|
-
* @param predicate - Function that receives
|
|
14
|
+
* @param predicate - Function that receives context and returns whether to apply middleware
|
|
15
15
|
* @param middleware - Middleware or array of middleware to apply
|
|
16
16
|
*
|
|
17
17
|
* @overload Apply middleware for matching pattern(s)
|
|
18
|
-
* @param patterns - Pattern or array of patterns to match
|
|
18
|
+
* @param patterns - Pattern or array of patterns to match displayName
|
|
19
19
|
* @param middleware - Middleware or array of middleware to apply
|
|
20
20
|
*
|
|
21
21
|
* Pattern types:
|
|
@@ -43,7 +43,7 @@ export declare function compose(...middlewares: StoreMiddleware[]): StoreMiddlew
|
|
|
43
43
|
*
|
|
44
44
|
* // Predicate function
|
|
45
45
|
* applyFor(
|
|
46
|
-
* (
|
|
46
|
+
* (ctx) => ctx.spec.options.meta?.persist === true,
|
|
47
47
|
* persistMiddleware
|
|
48
48
|
* );
|
|
49
49
|
*
|
|
@@ -51,13 +51,13 @@ export declare function compose(...middlewares: StoreMiddleware[]): StoreMiddlew
|
|
|
51
51
|
* applyFor("counterStore", [loggingMiddleware, devtoolsMiddleware]);
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
export declare function applyFor(predicate: (
|
|
54
|
+
export declare function applyFor(predicate: (ctx: StoreMiddlewareContext) => boolean, middleware: StoreMiddleware | StoreMiddleware[]): StoreMiddleware;
|
|
55
55
|
export declare function applyFor(patterns: SpecPattern | SpecPattern[], middleware: StoreMiddleware | StoreMiddleware[]): StoreMiddleware;
|
|
56
56
|
/**
|
|
57
57
|
* Apply middleware to all stores except those matching predicate or pattern(s).
|
|
58
58
|
*
|
|
59
59
|
* @overload Exclude stores matching predicate
|
|
60
|
-
* @param predicate - Function that receives
|
|
60
|
+
* @param predicate - Function that receives context and returns whether to exclude
|
|
61
61
|
* @param middleware - Middleware or array of middleware to apply
|
|
62
62
|
*
|
|
63
63
|
* @overload Exclude stores matching pattern(s)
|
|
@@ -68,7 +68,7 @@ export declare function applyFor(patterns: SpecPattern | SpecPattern[], middlewa
|
|
|
68
68
|
* ```ts
|
|
69
69
|
* // Exclude by predicate
|
|
70
70
|
* applyExcept(
|
|
71
|
-
* (
|
|
71
|
+
* (ctx) => ctx.displayName.startsWith("_"),
|
|
72
72
|
* loggingMiddleware
|
|
73
73
|
* );
|
|
74
74
|
*
|
|
@@ -83,6 +83,6 @@ export declare function applyFor(patterns: SpecPattern | SpecPattern[], middlewa
|
|
|
83
83
|
* applyExcept(/^(temp|cache)/, persistMiddleware);
|
|
84
84
|
* ```
|
|
85
85
|
*/
|
|
86
|
-
export declare function applyExcept(predicate: (
|
|
86
|
+
export declare function applyExcept(predicate: (ctx: StoreMiddlewareContext) => boolean, middleware: StoreMiddleware | StoreMiddleware[]): StoreMiddleware;
|
|
87
87
|
export declare function applyExcept(patterns: SpecPattern | SpecPattern[], middleware: StoreMiddleware | StoreMiddleware[]): StoreMiddleware;
|
|
88
88
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/core/middleware.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EAIvB,MAAM,UAAU,CAAC;AAElB,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAwD1C;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,WAAW,EAAE,eAAe,EAAE,GAAG,eAAe,CA+B1E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,QAAQ,CACtB,SAAS,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,EACnD,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,GAC9C,eAAe,CAAC;AACnB,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,WAAW,GAAG,WAAW,EAAE,EACrC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,GAC9C,eAAe,CAAC;AA0CnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,EACnD,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,GAC9C,eAAe,CAAC;AACnB,wBAAgB,WAAW,CACzB,QAAQ,EAAE,WAAW,GAAG,WAAW,EAAE,EACrC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,GAC9C,eAAe,CAAC"}
|
package/dist/core/pick.d.ts
CHANGED
|
@@ -10,20 +10,20 @@ import { PickEquality } from '../types';
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
12
|
* // Without pick: re-renders when ANY profile property changes
|
|
13
|
-
* useStore(({
|
|
14
|
-
* const [state] =
|
|
13
|
+
* useStore(({ get }) => {
|
|
14
|
+
* const [state] = get(userStore);
|
|
15
15
|
* return { name: state.profile.name }; // tracks "profile"
|
|
16
16
|
* });
|
|
17
17
|
*
|
|
18
18
|
* // With pick: re-renders only when profile.name changes
|
|
19
|
-
* useStore(({
|
|
20
|
-
* const [state] =
|
|
19
|
+
* useStore(({ get }) => {
|
|
20
|
+
* const [state] = get(userStore);
|
|
21
21
|
* return { name: pick(() => state.profile.name) };
|
|
22
22
|
* });
|
|
23
23
|
*
|
|
24
24
|
* // With custom equality
|
|
25
|
-
* useStore(({
|
|
26
|
-
* const [state] =
|
|
25
|
+
* useStore(({ get }) => {
|
|
26
|
+
* const [state] = get(userStore);
|
|
27
27
|
* return {
|
|
28
28
|
* profile: pick(
|
|
29
29
|
* () => ({ name: state.profile.name, age: state.profile.age }),
|
package/dist/core/pick.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/core/pick.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../../src/core/pick.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAyGxE"}
|