floppy-disk 3.0.0-alpha.3 → 3.0.0-beta.1

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.
@@ -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) => (<TStateSlice = QueryState<TData>>(options?: {
157
- /**
158
- * Whether the query should execute automatically on mount.
159
- *
160
- * @default true
161
- */
162
- enabled?: boolean;
163
- /**
164
- * Whether to keep previous successful data while a new variable is loading.
165
- *
166
- * @remarks
167
- * - Only applies when the query is in the `INITIAL` state (no data & no error).
168
- * - Intended for variable changes:
169
- * when switching from one variable to another, the previous data is temporarily shown
170
- * while the new execution is in progress.
171
- * - Once the new execution resolves (success or error), the previous data is no longer used.
172
- * - Prevents UI flicker (e.g. empty/loading state) during transitions.
173
- *
174
- * @example
175
- * // Switching from userId=1 → userId=2
176
- * // While loading userId=2, still show userId=1 data
177
- * useQuery({ id: userId }, { keepPreviousData: true });
178
- */ keepPreviousData?: boolean;
179
- }, selector?: (state: QueryState<TData>) => TStateSlice) => TStateSlice) & {
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
- const useStore = (options2 = {}, selector = identity) => {
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
@@ -2,7 +2,7 @@
2
2
  "name": "floppy-disk",
3
3
  "description": "Lightweight, simple, and powerful state management library",
4
4
  "private": false,
5
- "version": "3.0.0-alpha.3",
5
+ "version": "3.0.0-beta.1",
6
6
  "publishConfig": {
7
7
  "tag": "alpha"
8
8
  },
@@ -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) => (<TStateSlice = QueryState<TData>>(options?: {
157
- /**
158
- * Whether the query should execute automatically on mount.
159
- *
160
- * @default true
161
- */
162
- enabled?: boolean;
163
- /**
164
- * Whether to keep previous successful data while a new variable is loading.
165
- *
166
- * @remarks
167
- * - Only applies when the query is in the `INITIAL` state (no data & no error).
168
- * - Intended for variable changes:
169
- * when switching from one variable to another, the previous data is temporarily shown
170
- * while the new execution is in progress.
171
- * - Once the new execution resolves (success or error), the previous data is no longer used.
172
- * - Prevents UI flicker (e.g. empty/loading state) during transitions.
173
- *
174
- * @example
175
- * // Switching from userId=1 → userId=2
176
- * // While loading userId=2, still show userId=1 data
177
- * useQuery({ id: userId }, { keepPreviousData: true });
178
- */ keepPreviousData?: boolean;
179
- }, selector?: (state: QueryState<TData>) => TStateSlice) => TStateSlice) & {
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
- const useStore = (options2 = {}, selector = vanilla.identity) => {
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,