Skip to content

Commit

Permalink
refactor(*): unify & use noop (#8294)
Browse files Browse the repository at this point in the history
* refactor(*): unify & use noop

* chore: update

* fix(query-core): reflect tkdodo's review

* chore: resolve type error
  • Loading branch information
manudeli authored Nov 15, 2024
1 parent 7838edc commit 6c2a055
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/angular-query-experimental/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
return !!throwError
}

export function noop() {}
export function noop(): void {}
2 changes: 1 addition & 1 deletion packages/query-async-storage-persister/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function noop() {}
export function noop(): void {}
2 changes: 1 addition & 1 deletion packages/query-sync-storage-persister/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function noop() {}
export function noop(): void {}
2 changes: 1 addition & 1 deletion packages/react-query/src/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function useBaseQuery<
React.useCallback(
(onStoreChange) => {
const unsubscribe = isRestoring
? () => undefined
? noop
: observer.subscribe(notifyManager.batchCalls(onStoreChange))

// Update result to make sure we did not miss any query updates
Expand Down
3 changes: 2 additions & 1 deletion packages/react-query/src/useQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
shouldSuspend,
willFetch,
} from './suspense'
import { noop } from './utils'
import type {
DefinedUseQueryResult,
UseQueryOptions,
Expand Down Expand Up @@ -280,7 +281,7 @@ export function useQueries<
React.useCallback(
(onStoreChange) =>
isRestoring
? () => undefined
? noop
: observer.subscribe(notifyManager.batchCalls(onStoreChange)),
[observer, isRestoring],
),
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
return !!throwError
}

export function noop() {}
export function noop(): void {}
5 changes: 3 additions & 2 deletions packages/solid-query/src/createQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from 'solid-js'
import { useQueryClient } from './QueryClientProvider'
import { useIsRestoring } from './isRestoring'
import { noop } from './utils'
import type { CreateQueryResult, SolidQueryOptions } from './types'
import type { Accessor } from 'solid-js'
import type { QueryClient } from './QueryClient'
Expand Down Expand Up @@ -305,10 +306,10 @@ export function createQueries<
})
})

let unsubscribe: () => void = () => undefined
let unsubscribe = noop
createComputed<() => void>((cleanup) => {
cleanup?.()
unsubscribe = isRestoring() ? () => undefined : subscribeToObserver()
unsubscribe = isRestoring() ? noop : subscribeToObserver()
// cleanup needs to be scheduled after synchronous effects take place
return () => queueMicrotask(unsubscribe)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
return !!throwError
}

export function noop() {}
export function noop(): void {}
2 changes: 1 addition & 1 deletion packages/svelte-query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export function isSvelteStore<T extends object>(
return 'subscribe' in obj && typeof obj.subscribe === 'function'
}

export function noop() {}
export function noop(): void {}

0 comments on commit 6c2a055

Please sign in to comment.