floppy-disk 3.0.0-alpha.3 → 3.0.0-alpha.4
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/esm/react/create-query.d.mts +27 -24
- package/esm/react.mjs +11 -2
- package/package.json +1 -1
- package/react/create-query.d.ts +27 -24
- package/react.js +11 -2
|
@@ -153,30 +153,33 @@ export type QueryOptions<TData, TVariable extends Record<string, any>> = InitSto
|
|
|
153
153
|
* // ...
|
|
154
154
|
* }
|
|
155
155
|
*/
|
|
156
|
-
export declare const createQuery: <TData, TVariable extends Record<string, any> = never>(queryFn: (variable: TVariable, currentState: QueryState<TData>) => Promise<TData>, options?: QueryOptions<TData, TVariable>) => ((variable?: TVariable) =>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
156
|
+
export declare const createQuery: <TData, TVariable extends Record<string, any> = never>(queryFn: (variable: TVariable, currentState: QueryState<TData>) => Promise<TData>, options?: QueryOptions<TData, TVariable>) => ((variable?: TVariable) => {
|
|
157
|
+
<TStateSlice = QueryState<TData>>(options?: {
|
|
158
|
+
/**
|
|
159
|
+
* Whether the query should execute automatically on mount.
|
|
160
|
+
*
|
|
161
|
+
* @default true
|
|
162
|
+
*/
|
|
163
|
+
enabled?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Whether to keep previous successful data while a new variable is loading.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* - Only applies when the query is in the `INITIAL` state (no data & no error).
|
|
169
|
+
* - Intended for variable changes:
|
|
170
|
+
* when switching from one variable to another, the previous data is temporarily shown
|
|
171
|
+
* while the new execution is in progress.
|
|
172
|
+
* - Once the new execution resolves (success or error), the previous data is no longer used.
|
|
173
|
+
* - Prevents UI flicker (e.g. empty/loading state) during transitions.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // Switching from userId=1 → userId=2
|
|
177
|
+
* // While loading userId=2, still show userId=1 data
|
|
178
|
+
* useQuery({ id: userId }, { keepPreviousData: true });
|
|
179
|
+
*/ keepPreviousData?: boolean;
|
|
180
|
+
}, selector?: (state: QueryState<TData>) => TStateSlice): TStateSlice;
|
|
181
|
+
<TStateSlice = QueryState<TData>>(selector?: (state: QueryState<TData>) => TStateSlice): TStateSlice;
|
|
182
|
+
} & {
|
|
180
183
|
metadata: {
|
|
181
184
|
isInvalidated?: boolean;
|
|
182
185
|
promise?: Promise<QueryState<TData>> | undefined;
|
package/esm/react.mjs
CHANGED
|
@@ -323,7 +323,16 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
323
323
|
stores.set(variableHash, store);
|
|
324
324
|
internals.set(store, configureInternals(store, variable, variableHash));
|
|
325
325
|
}
|
|
326
|
-
|
|
326
|
+
function useStore(optionsOrSelector = {}, maybeSelector) {
|
|
327
|
+
let selector;
|
|
328
|
+
let options2;
|
|
329
|
+
if (typeof optionsOrSelector === "function") {
|
|
330
|
+
options2 = {};
|
|
331
|
+
selector = optionsOrSelector;
|
|
332
|
+
} else {
|
|
333
|
+
options2 = optionsOrSelector;
|
|
334
|
+
selector = maybeSelector || identity;
|
|
335
|
+
}
|
|
327
336
|
useStoreUpdateNotifier(store, selector);
|
|
328
337
|
useIsomorphicLayoutEffect(() => {
|
|
329
338
|
if (options2.enabled !== false) revalidate(store, variable, false);
|
|
@@ -337,7 +346,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
337
346
|
storeStateToBeUsed = { ...storeState, ...prevState.current };
|
|
338
347
|
}
|
|
339
348
|
return selector(storeStateToBeUsed);
|
|
340
|
-
}
|
|
349
|
+
}
|
|
341
350
|
return Object.assign(useStore, {
|
|
342
351
|
subscribe: store.subscribe,
|
|
343
352
|
getSubscribers: store.getSubscribers,
|
package/package.json
CHANGED
package/react/create-query.d.ts
CHANGED
|
@@ -153,30 +153,33 @@ export type QueryOptions<TData, TVariable extends Record<string, any>> = InitSto
|
|
|
153
153
|
* // ...
|
|
154
154
|
* }
|
|
155
155
|
*/
|
|
156
|
-
export declare const createQuery: <TData, TVariable extends Record<string, any> = never>(queryFn: (variable: TVariable, currentState: QueryState<TData>) => Promise<TData>, options?: QueryOptions<TData, TVariable>) => ((variable?: TVariable) =>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
156
|
+
export declare const createQuery: <TData, TVariable extends Record<string, any> = never>(queryFn: (variable: TVariable, currentState: QueryState<TData>) => Promise<TData>, options?: QueryOptions<TData, TVariable>) => ((variable?: TVariable) => {
|
|
157
|
+
<TStateSlice = QueryState<TData>>(options?: {
|
|
158
|
+
/**
|
|
159
|
+
* Whether the query should execute automatically on mount.
|
|
160
|
+
*
|
|
161
|
+
* @default true
|
|
162
|
+
*/
|
|
163
|
+
enabled?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Whether to keep previous successful data while a new variable is loading.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* - Only applies when the query is in the `INITIAL` state (no data & no error).
|
|
169
|
+
* - Intended for variable changes:
|
|
170
|
+
* when switching from one variable to another, the previous data is temporarily shown
|
|
171
|
+
* while the new execution is in progress.
|
|
172
|
+
* - Once the new execution resolves (success or error), the previous data is no longer used.
|
|
173
|
+
* - Prevents UI flicker (e.g. empty/loading state) during transitions.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // Switching from userId=1 → userId=2
|
|
177
|
+
* // While loading userId=2, still show userId=1 data
|
|
178
|
+
* useQuery({ id: userId }, { keepPreviousData: true });
|
|
179
|
+
*/ keepPreviousData?: boolean;
|
|
180
|
+
}, selector?: (state: QueryState<TData>) => TStateSlice): TStateSlice;
|
|
181
|
+
<TStateSlice = QueryState<TData>>(selector?: (state: QueryState<TData>) => TStateSlice): TStateSlice;
|
|
182
|
+
} & {
|
|
180
183
|
metadata: {
|
|
181
184
|
isInvalidated?: boolean;
|
|
182
185
|
promise?: Promise<QueryState<TData>> | undefined;
|
package/react.js
CHANGED
|
@@ -325,7 +325,16 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
325
325
|
stores.set(variableHash, store);
|
|
326
326
|
internals.set(store, configureInternals(store, variable, variableHash));
|
|
327
327
|
}
|
|
328
|
-
|
|
328
|
+
function useStore(optionsOrSelector = {}, maybeSelector) {
|
|
329
|
+
let selector;
|
|
330
|
+
let options2;
|
|
331
|
+
if (typeof optionsOrSelector === "function") {
|
|
332
|
+
options2 = {};
|
|
333
|
+
selector = optionsOrSelector;
|
|
334
|
+
} else {
|
|
335
|
+
options2 = optionsOrSelector;
|
|
336
|
+
selector = maybeSelector || vanilla.identity;
|
|
337
|
+
}
|
|
329
338
|
useStoreUpdateNotifier(store, selector);
|
|
330
339
|
useIsomorphicLayoutEffect(() => {
|
|
331
340
|
if (options2.enabled !== false) revalidate(store, variable, false);
|
|
@@ -339,7 +348,7 @@ const createQuery = (queryFn, options = {}) => {
|
|
|
339
348
|
storeStateToBeUsed = { ...storeState, ...prevState.current };
|
|
340
349
|
}
|
|
341
350
|
return selector(storeStateToBeUsed);
|
|
342
|
-
}
|
|
351
|
+
}
|
|
343
352
|
return Object.assign(useStore, {
|
|
344
353
|
subscribe: store.subscribe,
|
|
345
354
|
getSubscribers: store.getSubscribers,
|