floppy-disk 2.1.0-beta.2 → 2.1.0-beta.3

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.
@@ -103,7 +103,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
103
103
  isError: false;
104
104
  data: TData;
105
105
  response: TResponse;
106
- responseUpdatedAt: number;
106
+ responseUpdatedAt: number | null;
107
107
  } | {
108
108
  status: 'error';
109
109
  isLoading: false;
@@ -186,6 +186,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
186
186
  setInitialResponse: (options: {
187
187
  key?: TKey;
188
188
  response: TResponse;
189
+ skipRevalidation?: boolean;
189
190
  }) => void;
190
191
  /**
191
192
  * Set query state (data, error, etc) to initial state.
@@ -166,6 +166,9 @@ export const createQuery = (queryFn, options = {}) => {
166
166
  forceFetch();
167
167
  };
168
168
  const fetchNextPage = () => {
169
+ if (typeof options.getNextPageParam !== 'function') {
170
+ return console.warn('fetchNextPage with invalid getNextPageParam option');
171
+ }
169
172
  const state = get();
170
173
  const { isLoading, isWaitingNextPage, data, hasNextPage, pageParam, pageParams } = state;
171
174
  if (isLoading)
@@ -271,7 +274,7 @@ export const createQuery = (queryFn, options = {}) => {
271
274
  },
272
275
  };
273
276
  })());
274
- useQuery.setInitialResponse = ({ key, response }) => {
277
+ useQuery.setInitialResponse = ({ key, response, skipRevalidation }) => {
275
278
  // eslint-disable-next-line react-hooks/rules-of-hooks
276
279
  useState(() => {
277
280
  if (response === undefined || useQuery.get(key).data)
@@ -283,7 +286,7 @@ export const createQuery = (queryFn, options = {}) => {
283
286
  isSuccess: true,
284
287
  isError: false,
285
288
  response,
286
- responseUpdatedAt: Date.now(),
289
+ responseUpdatedAt: skipRevalidation ? Date.now() : null,
287
290
  data: select(response, { key: key, data: null }),
288
291
  pageParam: newPageParam,
289
292
  pageParams: [undefined, newPageParam],
@@ -103,7 +103,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
103
103
  isError: false;
104
104
  data: TData;
105
105
  response: TResponse;
106
- responseUpdatedAt: number;
106
+ responseUpdatedAt: number | null;
107
107
  } | {
108
108
  status: 'error';
109
109
  isLoading: false;
@@ -186,6 +186,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
186
186
  setInitialResponse: (options: {
187
187
  key?: TKey;
188
188
  response: TResponse;
189
+ skipRevalidation?: boolean;
189
190
  }) => void;
190
191
  /**
191
192
  * Set query state (data, error, etc) to initial state.
@@ -166,6 +166,9 @@ export const createQuery = (queryFn, options = {}) => {
166
166
  forceFetch();
167
167
  };
168
168
  const fetchNextPage = () => {
169
+ if (typeof options.getNextPageParam !== 'function') {
170
+ return console.warn('fetchNextPage with invalid getNextPageParam option');
171
+ }
169
172
  const state = get();
170
173
  const { isLoading, isWaitingNextPage, data, hasNextPage, pageParam, pageParams } = state;
171
174
  if (isLoading)
@@ -271,7 +274,7 @@ export const createQuery = (queryFn, options = {}) => {
271
274
  },
272
275
  };
273
276
  })());
274
- useQuery.setInitialResponse = ({ key, response }) => {
277
+ useQuery.setInitialResponse = ({ key, response, skipRevalidation }) => {
275
278
  // eslint-disable-next-line react-hooks/rules-of-hooks
276
279
  useState(() => {
277
280
  if (response === undefined || useQuery.get(key).data)
@@ -283,7 +286,7 @@ export const createQuery = (queryFn, options = {}) => {
283
286
  isSuccess: true,
284
287
  isError: false,
285
288
  response,
286
- responseUpdatedAt: Date.now(),
289
+ responseUpdatedAt: skipRevalidation ? Date.now() : null,
287
290
  data: select(response, { key: key, data: null }),
288
291
  pageParam: newPageParam,
289
292
  pageParams: [undefined, newPageParam],
@@ -103,7 +103,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
103
103
  isError: false;
104
104
  data: TData;
105
105
  response: TResponse;
106
- responseUpdatedAt: number;
106
+ responseUpdatedAt: number | null;
107
107
  } | {
108
108
  status: 'error';
109
109
  isLoading: false;
@@ -186,6 +186,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
186
186
  setInitialResponse: (options: {
187
187
  key?: TKey;
188
188
  response: TResponse;
189
+ skipRevalidation?: boolean;
189
190
  }) => void;
190
191
  /**
191
192
  * Set query state (data, error, etc) to initial state.
@@ -169,6 +169,9 @@ const createQuery = (queryFn, options = {}) => {
169
169
  forceFetch();
170
170
  };
171
171
  const fetchNextPage = () => {
172
+ if (typeof options.getNextPageParam !== 'function') {
173
+ return console.warn('fetchNextPage with invalid getNextPageParam option');
174
+ }
172
175
  const state = get();
173
176
  const { isLoading, isWaitingNextPage, data, hasNextPage, pageParam, pageParams } = state;
174
177
  if (isLoading)
@@ -274,7 +277,7 @@ const createQuery = (queryFn, options = {}) => {
274
277
  },
275
278
  };
276
279
  })());
277
- useQuery.setInitialResponse = ({ key, response }) => {
280
+ useQuery.setInitialResponse = ({ key, response, skipRevalidation }) => {
278
281
  // eslint-disable-next-line react-hooks/rules-of-hooks
279
282
  (0, hooks_1.useState)(() => {
280
283
  if (response === undefined || useQuery.get(key).data)
@@ -286,7 +289,7 @@ const createQuery = (queryFn, options = {}) => {
286
289
  isSuccess: true,
287
290
  isError: false,
288
291
  response,
289
- responseUpdatedAt: Date.now(),
292
+ responseUpdatedAt: skipRevalidation ? Date.now() : null,
290
293
  data: select(response, { key: key, data: null }),
291
294
  pageParam: newPageParam,
292
295
  pageParams: [undefined, newPageParam],
@@ -103,7 +103,7 @@ export type QueryState<TKey extends StoreKey = StoreKey, TResponse = any, TData
103
103
  isError: false;
104
104
  data: TData;
105
105
  response: TResponse;
106
- responseUpdatedAt: number;
106
+ responseUpdatedAt: number | null;
107
107
  } | {
108
108
  status: 'error';
109
109
  isLoading: false;
@@ -186,6 +186,7 @@ export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData =
186
186
  setInitialResponse: (options: {
187
187
  key?: TKey;
188
188
  response: TResponse;
189
+ skipRevalidation?: boolean;
189
190
  }) => void;
190
191
  /**
191
192
  * Set query state (data, error, etc) to initial state.
@@ -169,6 +169,9 @@ const createQuery = (queryFn, options = {}) => {
169
169
  forceFetch();
170
170
  };
171
171
  const fetchNextPage = () => {
172
+ if (typeof options.getNextPageParam !== 'function') {
173
+ return console.warn('fetchNextPage with invalid getNextPageParam option');
174
+ }
172
175
  const state = get();
173
176
  const { isLoading, isWaitingNextPage, data, hasNextPage, pageParam, pageParams } = state;
174
177
  if (isLoading)
@@ -274,7 +277,7 @@ const createQuery = (queryFn, options = {}) => {
274
277
  },
275
278
  };
276
279
  })());
277
- useQuery.setInitialResponse = ({ key, response }) => {
280
+ useQuery.setInitialResponse = ({ key, response, skipRevalidation }) => {
278
281
  // eslint-disable-next-line react-hooks/rules-of-hooks
279
282
  (0, react_1.useState)(() => {
280
283
  if (response === undefined || useQuery.get(key).data)
@@ -286,7 +289,7 @@ const createQuery = (queryFn, options = {}) => {
286
289
  isSuccess: true,
287
290
  isError: false,
288
291
  response,
289
- responseUpdatedAt: Date.now(),
292
+ responseUpdatedAt: skipRevalidation ? Date.now() : null,
290
293
  data: select(response, { key: key, data: null }),
291
294
  pageParam: newPageParam,
292
295
  pageParams: [undefined, newPageParam],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.3",
4
4
  "description": "FloppyDisk - lightweight, simple, and powerful state management library",
5
5
  "keywords": [
6
6
  "state",