Skip to content

Commit f940937

Browse files
committed
refactor: rename resolveValueOrFunction to resolveOption for consistency
1 parent d486197 commit f940937

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

packages/query-core/src/query.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
ensureQueryFn,
33
noop,
44
replaceData,
5-
resolveValueOrFunction,
5+
resolveOption,
66
skipToken,
77
timeUntilStale,
88
} from './utils'
@@ -255,7 +255,7 @@ export class Query<
255255
isActive(): boolean {
256256
return this.observers.some(
257257
(observer) =>
258-
resolveValueOrFunction(observer.options.enabled, this) !== false,
258+
resolveOption(observer.options.enabled, this) !== false,
259259
)
260260
}
261261

@@ -274,7 +274,7 @@ export class Query<
274274
if (this.getObserversCount() > 0) {
275275
return this.observers.some(
276276
(observer) =>
277-
resolveValueOrFunction(observer.options.staleTime, this) === 'static',
277+
resolveOption(observer.options.staleTime, this) === 'static',
278278
)
279279
}
280280

@@ -690,12 +690,12 @@ function getDefaultState<
690690
>(
691691
options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
692692
): QueryState<TData, TError> {
693-
const data = resolveValueOrFunction(options.initialData)
693+
const data = resolveOption(options.initialData)
694694

695695
const hasData = data !== undefined
696696

697697
const initialDataUpdatedAt = hasData
698-
? resolveValueOrFunction(options.initialDataUpdatedAt)
698+
? resolveOption(options.initialDataUpdatedAt)
699699
: 0
700700

701701
return {

packages/query-core/src/queryClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
hashQueryKeyByOptions,
55
noop,
66
partialMatchKey,
7-
resolveValueOrFunction,
7+
resolveOption,
88
skipToken,
99
} from './utils'
1010
import { QueryCache } from './queryCache'
@@ -156,7 +156,7 @@ export class QueryClient {
156156
if (
157157
options.revalidateIfStale &&
158158
query.isStaleByTime(
159-
resolveValueOrFunction(defaultedOptions.staleTime, query),
159+
resolveOption(defaultedOptions.staleTime, query),
160160
)
161161
) {
162162
void this.prefetchQuery(defaultedOptions)

packages/query-core/src/queryObserver.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
isValidTimeout,
99
noop,
1010
replaceData,
11-
resolveValueOrFunction,
11+
resolveOption,
1212
shallowEqualObjects,
1313
timeUntilStale,
1414
} from './utils'
@@ -155,7 +155,7 @@ export class QueryObserver<
155155
this.options.enabled !== undefined &&
156156
typeof this.options.enabled !== 'boolean' &&
157157
typeof this.options.enabled !== 'function' &&
158-
typeof resolveValueOrFunction(
158+
typeof resolveOption(
159159
this.options.enabled,
160160
this.#currentQuery,
161161
) !== 'boolean'
@@ -201,10 +201,10 @@ export class QueryObserver<
201201
if (
202202
mounted &&
203203
(this.#currentQuery !== prevQuery ||
204-
resolveValueOrFunction(this.options.enabled, this.#currentQuery) !==
205-
resolveValueOrFunction(prevOptions.enabled, this.#currentQuery) ||
206-
resolveValueOrFunction(this.options.staleTime, this.#currentQuery) !==
207-
resolveValueOrFunction(prevOptions.staleTime, this.#currentQuery))
204+
resolveOption(this.options.enabled, this.#currentQuery) !==
205+
resolveOption(prevOptions.enabled, this.#currentQuery) ||
206+
resolveOption(this.options.staleTime, this.#currentQuery) !==
207+
resolveOption(prevOptions.staleTime, this.#currentQuery))
208208
) {
209209
this.#updateStaleTimeout()
210210
}
@@ -215,8 +215,8 @@ export class QueryObserver<
215215
if (
216216
mounted &&
217217
(this.#currentQuery !== prevQuery ||
218-
resolveValueOrFunction(this.options.enabled, this.#currentQuery) !==
219-
resolveValueOrFunction(prevOptions.enabled, this.#currentQuery) ||
218+
resolveOption(this.options.enabled, this.#currentQuery) !==
219+
resolveOption(prevOptions.enabled, this.#currentQuery) ||
220220
nextRefetchInterval !== this.#currentRefetchInterval)
221221
) {
222222
this.#updateRefetchInterval(nextRefetchInterval)
@@ -344,7 +344,7 @@ export class QueryObserver<
344344

345345
#updateStaleTimeout(): void {
346346
this.#clearStaleTimeout()
347-
const staleTime = resolveValueOrFunction(
347+
const staleTime = resolveOption(
348348
this.options.staleTime,
349349
this.#currentQuery,
350350
)
@@ -368,7 +368,7 @@ export class QueryObserver<
368368

369369
#computeRefetchInterval() {
370370
return (
371-
resolveValueOrFunction(
371+
resolveOption(
372372
this.options.refetchInterval,
373373
this.#currentQuery,
374374
) ?? false
@@ -382,7 +382,7 @@ export class QueryObserver<
382382

383383
if (
384384
isServer ||
385-
resolveValueOrFunction(this.options.enabled, this.#currentQuery) ===
385+
resolveOption(this.options.enabled, this.#currentQuery) ===
386386
false ||
387387
!isValidTimeout(this.#currentRefetchInterval) ||
388388
this.#currentRefetchInterval === 0
@@ -491,7 +491,7 @@ export class QueryObserver<
491491
skipSelect = true
492492
} else {
493493
// compute placeholderData
494-
placeholderData = resolveValueOrFunction(
494+
placeholderData = resolveOption(
495495
options.placeholderData,
496496
this.#lastQueryWithDefinedData?.state.data,
497497
this.#lastQueryWithDefinedData as any,
@@ -659,7 +659,7 @@ export class QueryObserver<
659659

660660
const { notifyOnChangeProps } = this.options
661661
const notifyOnChangePropsValue =
662-
resolveValueOrFunction(notifyOnChangeProps)
662+
resolveOption(notifyOnChangeProps)
663663

664664
if (
665665
notifyOnChangePropsValue === 'all' ||
@@ -737,7 +737,7 @@ function shouldLoadOnMount(
737737
options: QueryObserverOptions<any, any, any, any>,
738738
): boolean {
739739
return (
740-
resolveValueOrFunction(options.enabled, query) !== false &&
740+
resolveOption(options.enabled, query) !== false &&
741741
query.state.data === undefined &&
742742
!(query.state.status === 'error' && options.retryOnMount === false)
743743
)
@@ -762,10 +762,10 @@ function shouldFetchOn(
762762
(typeof options)['refetchOnReconnect'],
763763
) {
764764
if (
765-
resolveValueOrFunction(options.enabled, query) !== false &&
766-
resolveValueOrFunction(options.staleTime, query) !== 'static'
765+
resolveOption(options.enabled, query) !== false &&
766+
resolveOption(options.staleTime, query) !== 'static'
767767
) {
768-
const value = resolveValueOrFunction(field, query)
768+
const value = resolveOption(field, query)
769769

770770
return value === 'always' || (value !== false && isStale(query, options))
771771
}
@@ -780,7 +780,7 @@ function shouldFetchOptionally(
780780
): boolean {
781781
return (
782782
(query !== prevQuery ||
783-
resolveValueOrFunction(prevOptions.enabled, query) === false) &&
783+
resolveOption(prevOptions.enabled, query) === false) &&
784784
(!options.suspense || query.state.status !== 'error') &&
785785
isStale(query, options)
786786
)
@@ -791,8 +791,8 @@ function isStale(
791791
options: QueryObserverOptions<any, any, any, any, any>,
792792
): boolean {
793793
return (
794-
resolveValueOrFunction(options.enabled, query) !== false &&
795-
query.isStaleByTime(resolveValueOrFunction(options.staleTime, query))
794+
resolveOption(options.enabled, query) !== false &&
795+
query.isStaleByTime(resolveOption(options.staleTime, query))
796796
)
797797
}
798798

packages/query-core/src/retryer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { focusManager } from './focusManager'
22
import { onlineManager } from './onlineManager'
33
import { pendingThenable } from './thenable'
4-
import { isServer, resolveValueOrFunction, sleep } from './utils'
4+
import { isServer, resolveOption, sleep } from './utils'
55
import type { CancelOptions, DefaultError, NetworkMode } from './types'
66

77
// TYPES
@@ -166,7 +166,7 @@ export function createRetryer<TData = unknown, TError = DefaultError>(
166166
// Do we need to retry the request?
167167
const retry = config.retry ?? (isServer ? 0 : 3)
168168
const retryDelay = config.retryDelay ?? defaultRetryDelay
169-
const delay = resolveValueOrFunction(retryDelay, failureCount, error)
169+
const delay = resolveOption(retryDelay, failureCount, error)
170170
const shouldRetry =
171171
retry === true ||
172172
(typeof retry === 'number' && failureCount < retry) ||

packages/query-core/src/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,20 @@ function isFunctionVariant<T, TArgs extends Array<any> = []>(
131131
* ```ts
132132
* // Zero-argument function resolution (like initialData)
133133
* const initialData: string | (() => string) = 'hello'
134-
* const resolved = resolveValueOrFunction(initialData) // 'hello'
134+
* const resolved = resolveOption(initialData) // 'hello'
135135
*
136136
* const initialDataFn: string | (() => string) = () => 'world'
137-
* const resolved2 = resolveValueOrFunction(initialDataFn) // 'world'
137+
* const resolved2 = resolveOption(initialDataFn) // 'world'
138138
* ```
139139
*
140140
* @example
141141
* ```ts
142142
* // Function with arguments (like staleTime, retryDelay)
143143
* const staleTime: number | ((query: Query) => number) = (query) => query.state.dataUpdatedAt + 5000
144-
* const resolved = resolveValueOrFunction(staleTime, query) // number
144+
* const resolved = resolveOption(staleTime, query) // number
145145
*
146146
* const retryDelay: number | ((failureCount: number, error: Error) => number) = 1000
147-
* const resolved2 = resolveValueOrFunction(retryDelay, 3, new Error()) // 1000
147+
* const resolved2 = resolveOption(retryDelay, 3, new Error()) // 1000
148148
* ```
149149
*
150150
* @example
@@ -155,10 +155,10 @@ function isFunctionVariant<T, TArgs extends Array<any> = []>(
155155
* // : retryDelay
156156
*
157157
* // With:
158-
* const delay = resolveValueOrFunction(retryDelay, failureCount, error)
158+
* const delay = resolveOption(retryDelay, failureCount, error)
159159
* ```
160160
*/
161-
export function resolveValueOrFunction<T, TArgs extends Array<any>>(
161+
export function resolveOption<T, TArgs extends Array<any>>(
162162
value: T | ((...args: TArgs) => T),
163163
...args: TArgs
164164
): T {

0 commit comments

Comments
 (0)