Skip to content

Commit

Permalink
refactor(*): change noop function return type from undefined to void (#…
Browse files Browse the repository at this point in the history
…8299)

* refactor(*): use noop

* refactor: separate noop and returnUndefined functions with type refinement

Co-authored-by: Jonghyeon Ko <[email protected]>
Co-authored-by: Sol Lee <[email protected]>

* refactor: optimize bundle size with type re-assertion

* fix: Prevent type error by overloading noop function

* fix: remove jsdoc

* fix

* revert

* revert at react-query and angular-query-experimental

---------

Co-authored-by: Jonghyeon Ko <[email protected]>
Co-authored-by: Sol Lee <[email protected]>
Co-authored-by: Dominik Dorfmeister <[email protected]>
  • Loading branch information
4 people authored Nov 19, 2024
1 parent fadfbde commit 7d36089
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/angular-query-experimental/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { QueryClient, onlineManager } from '@tanstack/query-core'
import { isPlatformBrowser } from '@angular/common'
import { isDevMode } from './util/is-dev-mode/is-dev-mode'
import { noop } from './util'
import type { EnvironmentProviders, Provider } from '@angular/core'
import type {
DevtoolsButtonPosition,
Expand Down Expand Up @@ -251,7 +252,7 @@ export function withDevtools(
provide: ENVIRONMENT_INITIALIZER,
multi: true,
useFactory: () => {
if (!isPlatformBrowser(inject(PLATFORM_ID))) return () => {}
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop
const injector = inject(Injector)
const options = computed(() =>
runInInjectionContext(injector, () => optionsFn?.() ?? {}),
Expand Down
4 changes: 3 additions & 1 deletion packages/query-async-storage-persister/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export function noop(): void {}
export function noop(): void
export function noop(): undefined
export function noop() {}
6 changes: 3 additions & 3 deletions packages/query-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export type QueryTypeFilter = 'all' | 'active' | 'inactive'

export const isServer = typeof window === 'undefined' || 'Deno' in globalThis

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

export function functionalUpdate<TInput, TOutput>(
updater: Updater<TInput, TOutput>,
Expand Down
2 changes: 1 addition & 1 deletion packages/query-sync-storage-persister/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function createSyncStoragePersister({

return {
persistClient: noop,
restoreClient: () => undefined,
restoreClient: noop,
removeClient: noop,
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/query-sync-storage-persister/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export function noop(): void {}
export function noop(): void
export function noop(): undefined
export function noop() {}
4 changes: 2 additions & 2 deletions packages/svelte-query/src/createBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { derived, get, readable } from 'svelte/store'
import { notifyManager } from '@tanstack/query-core'
import { useIsRestoring } from './useIsRestoring.js'
import { useQueryClient } from './useQueryClient.js'
import { isSvelteStore } from './utils.js'
import { isSvelteStore, noop } from './utils.js'
import type {
QueryClient,
QueryKey,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function createBaseQuery<
QueryObserverResult<TData, TError>
>(isRestoring, ($isRestoring, set) => {
const unsubscribe = $isRestoring
? () => undefined
? noop
: observer.subscribe(notifyManager.batchCalls(set))
observer.updateResult()
return unsubscribe
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte-query/src/createQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QueriesObserver, notifyManager } from '@tanstack/query-core'
import { derived, get, readable } from 'svelte/store'
import { useIsRestoring } from './useIsRestoring.js'
import { useQueryClient } from './useQueryClient.js'
import { isSvelteStore } from './utils.js'
import { isSvelteStore, noop } from './utils.js'
import type { Readable } from 'svelte/store'
import type { StoreOrVal } from './types.js'
import type {
Expand Down Expand Up @@ -253,7 +253,7 @@ export function createQueries<

const result = derived([isRestoring], ([$isRestoring], set) => {
const unsubscribe = $isRestoring
? () => undefined
? noop
: observer.subscribe(notifyManager.batchCalls(set))

return () => unsubscribe()
Expand Down

0 comments on commit 7d36089

Please sign in to comment.