floppy-disk 2.4.0-beta.2 → 2.4.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.
@@ -200,7 +200,7 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
200
200
  *
201
201
  * If the query is on error state, the polling interval will be disabled, and it will use `retry` instead.
202
202
  */
203
- refetchInterval?: number | false | (() => number | false);
203
+ refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
204
204
  };
205
205
  export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
206
206
  /**
@@ -94,7 +94,7 @@ export const createQuery = (queryFn, options = {}) => {
94
94
  callQuery();
95
95
  return;
96
96
  }
97
- set({
97
+ const nextState = {
98
98
  isWaiting: false,
99
99
  status: 'success',
100
100
  isLoading: false,
@@ -115,13 +115,15 @@ export const createQuery = (queryFn, options = {}) => {
115
115
  pageParam: newPageParam,
116
116
  pageParams: newPageParams,
117
117
  hasNextPage: hasValue(newPageParam),
118
- });
119
- const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
118
+ };
119
+ const refetchIntervalValue = typeof window !== 'undefined' &&
120
+ getValueOrComputedValue(refetchInterval, { ...get(), ...nextState });
120
121
  if (refetchIntervalValue) {
121
122
  refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
122
123
  forceFetch();
123
124
  }, refetchIntervalValue));
124
125
  }
126
+ set(nextState);
125
127
  onSuccess(response, stateBeforeCallQuery);
126
128
  resolve(get());
127
129
  })
@@ -247,7 +249,7 @@ export const createQuery = (queryFn, options = {}) => {
247
249
  defaultDeps,
248
250
  onFirstSubscribe: (state) => {
249
251
  if (state.isSuccess) {
250
- const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
252
+ const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval, state);
251
253
  if (refetchIntervalValue) {
252
254
  refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
253
255
  state.forceFetch();
@@ -199,7 +199,7 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
199
199
  *
200
200
  * If the query is on error state, the polling interval will be disabled, and it will use `retry` instead.
201
201
  */
202
- refetchInterval?: number | false | (() => number | false);
202
+ refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
203
203
  };
204
204
  export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
205
205
  /**
@@ -93,7 +93,7 @@ export const createQuery = (queryFn, options = {}) => {
93
93
  callQuery();
94
94
  return;
95
95
  }
96
- set({
96
+ const nextState = {
97
97
  isWaiting: false,
98
98
  status: 'success',
99
99
  isLoading: false,
@@ -114,13 +114,15 @@ export const createQuery = (queryFn, options = {}) => {
114
114
  pageParam: newPageParam,
115
115
  pageParams: newPageParams,
116
116
  hasNextPage: hasValue(newPageParam),
117
- });
118
- const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
117
+ };
118
+ const refetchIntervalValue = typeof window !== 'undefined' &&
119
+ getValueOrComputedValue(refetchInterval, { ...get(), ...nextState });
119
120
  if (refetchIntervalValue) {
120
121
  refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
121
122
  forceFetch();
122
123
  }, refetchIntervalValue));
123
124
  }
125
+ set(nextState);
124
126
  onSuccess(response, stateBeforeCallQuery);
125
127
  resolve(get());
126
128
  })
@@ -246,7 +248,7 @@ export const createQuery = (queryFn, options = {}) => {
246
248
  defaultDeps,
247
249
  onFirstSubscribe: (state) => {
248
250
  if (state.isSuccess) {
249
- const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval);
251
+ const refetchIntervalValue = typeof window !== 'undefined' && getValueOrComputedValue(refetchInterval, state);
250
252
  if (refetchIntervalValue) {
251
253
  refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
252
254
  state.forceFetch();
@@ -200,7 +200,7 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
200
200
  *
201
201
  * If the query is on error state, the polling interval will be disabled, and it will use `retry` instead.
202
202
  */
203
- refetchInterval?: number | false | (() => number | false);
203
+ refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
204
204
  };
205
205
  export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
206
206
  /**
@@ -97,7 +97,7 @@ const createQuery = (queryFn, options = {}) => {
97
97
  callQuery();
98
98
  return;
99
99
  }
100
- set({
100
+ const nextState = {
101
101
  isWaiting: false,
102
102
  status: 'success',
103
103
  isLoading: false,
@@ -118,13 +118,15 @@ const createQuery = (queryFn, options = {}) => {
118
118
  pageParam: newPageParam,
119
119
  pageParams: newPageParams,
120
120
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
121
- });
122
- const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
121
+ };
122
+ const refetchIntervalValue = typeof window !== 'undefined' &&
123
+ (0, utils_1.getValueOrComputedValue)(refetchInterval, { ...get(), ...nextState });
123
124
  if (refetchIntervalValue) {
124
125
  refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
125
126
  forceFetch();
126
127
  }, refetchIntervalValue));
127
128
  }
129
+ set(nextState);
128
130
  onSuccess(response, stateBeforeCallQuery);
129
131
  resolve(get());
130
132
  })
@@ -250,7 +252,7 @@ const createQuery = (queryFn, options = {}) => {
250
252
  defaultDeps,
251
253
  onFirstSubscribe: (state) => {
252
254
  if (state.isSuccess) {
253
- const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
255
+ const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval, state);
254
256
  if (refetchIntervalValue) {
255
257
  refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
256
258
  state.forceFetch();
@@ -199,7 +199,7 @@ export type CreateQueryOptions<TKey extends StoreKey = StoreKey, TResponse = any
199
199
  *
200
200
  * If the query is on error state, the polling interval will be disabled, and it will use `retry` instead.
201
201
  */
202
- refetchInterval?: number | false | (() => number | false);
202
+ refetchInterval?: number | false | ((state: QueryState<TKey, TResponse, TData, TError>) => number | false);
203
203
  };
204
204
  export type UseQuery<TKey extends StoreKey = StoreKey, TResponse = any, TData = TResponse, TError = unknown> = UseStores<TKey, QueryState<TKey, TResponse, TData, TError>> & {
205
205
  /**
@@ -96,7 +96,7 @@ const createQuery = (queryFn, options = {}) => {
96
96
  callQuery();
97
97
  return;
98
98
  }
99
- set({
99
+ const nextState = {
100
100
  isWaiting: false,
101
101
  status: 'success',
102
102
  isLoading: false,
@@ -117,13 +117,15 @@ const createQuery = (queryFn, options = {}) => {
117
117
  pageParam: newPageParam,
118
118
  pageParams: newPageParams,
119
119
  hasNextPage: (0, utils_1.hasValue)(newPageParam),
120
- });
121
- const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
120
+ };
121
+ const refetchIntervalValue = typeof window !== 'undefined' &&
122
+ (0, utils_1.getValueOrComputedValue)(refetchInterval, { ...get(), ...nextState });
122
123
  if (refetchIntervalValue) {
123
124
  refetchIntervalTimeoutId.set(keyHash, window.setTimeout(() => {
124
125
  forceFetch();
125
126
  }, refetchIntervalValue));
126
127
  }
128
+ set(nextState);
127
129
  onSuccess(response, stateBeforeCallQuery);
128
130
  resolve(get());
129
131
  })
@@ -249,7 +251,7 @@ const createQuery = (queryFn, options = {}) => {
249
251
  defaultDeps,
250
252
  onFirstSubscribe: (state) => {
251
253
  if (state.isSuccess) {
252
- const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval);
254
+ const refetchIntervalValue = typeof window !== 'undefined' && (0, utils_1.getValueOrComputedValue)(refetchInterval, state);
253
255
  if (refetchIntervalValue) {
254
256
  refetchIntervalTimeoutId.set(state.keyHash, window.setTimeout(() => {
255
257
  state.forceFetch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floppy-disk",
3
- "version": "2.4.0-beta.2",
3
+ "version": "2.4.0-beta.3",
4
4
  "description": "FloppyDisk - lightweight, simple, and powerful state management library",
5
5
  "keywords": [
6
6
  "state",