Skip to content

Commit 6c2a055

Browse files
authored
refactor(*): unify & use noop (#8294)
* refactor(*): unify & use noop * chore: update * fix(query-core): reflect tkdodo's review * chore: resolve type error
1 parent 7838edc commit 6c2a055

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

packages/angular-query-experimental/src/util/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
1010
return !!throwError
1111
}
1212

13-
export function noop() {}
13+
export function noop(): void {}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export function noop() {}
1+
export function noop(): void {}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export function noop() {}
1+
export function noop(): void {}

packages/react-query/src/useBaseQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function useBaseQuery<
8888
React.useCallback(
8989
(onStoreChange) => {
9090
const unsubscribe = isRestoring
91-
? () => undefined
91+
? noop
9292
: observer.subscribe(notifyManager.batchCalls(onStoreChange))
9393

9494
// Update result to make sure we did not miss any query updates

packages/react-query/src/useQueries.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
shouldSuspend,
2121
willFetch,
2222
} from './suspense'
23+
import { noop } from './utils'
2324
import type {
2425
DefinedUseQueryResult,
2526
UseQueryOptions,
@@ -280,7 +281,7 @@ export function useQueries<
280281
React.useCallback(
281282
(onStoreChange) =>
282283
isRestoring
283-
? () => undefined
284+
? noop
284285
: observer.subscribe(notifyManager.batchCalls(onStoreChange)),
285286
[observer, isRestoring],
286287
),

packages/react-query/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
1010
return !!throwError
1111
}
1212

13-
export function noop() {}
13+
export function noop(): void {}

packages/solid-query/src/createQueries.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from 'solid-js'
1414
import { useQueryClient } from './QueryClientProvider'
1515
import { useIsRestoring } from './isRestoring'
16+
import { noop } from './utils'
1617
import type { CreateQueryResult, SolidQueryOptions } from './types'
1718
import type { Accessor } from 'solid-js'
1819
import type { QueryClient } from './QueryClient'
@@ -305,10 +306,10 @@ export function createQueries<
305306
})
306307
})
307308

308-
let unsubscribe: () => void = () => undefined
309+
let unsubscribe = noop
309310
createComputed<() => void>((cleanup) => {
310311
cleanup?.()
311-
unsubscribe = isRestoring() ? () => undefined : subscribeToObserver()
312+
unsubscribe = isRestoring() ? noop : subscribeToObserver()
312313
// cleanup needs to be scheduled after synchronous effects take place
313314
return () => queueMicrotask(unsubscribe)
314315
})

packages/solid-query/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
1010
return !!throwError
1111
}
1212

13-
export function noop() {}
13+
export function noop(): void {}

packages/svelte-query/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export function isSvelteStore<T extends object>(
77
return 'subscribe' in obj && typeof obj.subscribe === 'function'
88
}
99

10-
export function noop() {}
10+
export function noop(): void {}

0 commit comments

Comments
 (0)