From c76f36fe941ab11538482f935e1bc591bfd00640 Mon Sep 17 00:00:00 2001 From: Saul Lee Date: Sat, 24 Feb 2024 19:28:21 +0900 Subject: [PATCH 1/3] refactor(*): Import noop function from utils --- packages/angular-query-experimental/src/inject-mutation.ts | 3 +-- packages/query-async-storage-persister/src/asyncThrottle.ts | 6 ++---- packages/query-async-storage-persister/src/index.ts | 3 +-- packages/query-sync-storage-persister/src/index.ts | 3 +-- packages/react-query/src/useMutation.ts | 3 +-- packages/solid-query/src/createMutation.ts | 3 +-- packages/svelte-query/src/createMutation.ts | 3 +-- 7 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/angular-query-experimental/src/inject-mutation.ts b/packages/angular-query-experimental/src/inject-mutation.ts index 41e47411b2..5943351506 100644 --- a/packages/angular-query-experimental/src/inject-mutation.ts +++ b/packages/angular-query-experimental/src/inject-mutation.ts @@ -1,5 +1,6 @@ import { DestroyRef, computed, effect, inject, signal } from '@angular/core' import { MutationObserver, notifyManager } from '@tanstack/query-core' +import { noop } from '../../query-core/src/utils' import { assertInjector } from './util/assert-injector/assert-injector' import { signalProxy } from './signal-proxy' import { injectQueryClient } from './inject-query-client' @@ -64,5 +65,3 @@ export function injectMutation< > }) } - -function noop() {} diff --git a/packages/query-async-storage-persister/src/asyncThrottle.ts b/packages/query-async-storage-persister/src/asyncThrottle.ts index 8f5157d56e..c295c5eb34 100644 --- a/packages/query-async-storage-persister/src/asyncThrottle.ts +++ b/packages/query-async-storage-persister/src/asyncThrottle.ts @@ -1,12 +1,10 @@ +import { noop } from '../../query-core/src/utils' + export interface AsyncThrottleOptions { interval?: number onError?: (error: unknown) => void } -const noop = () => { - /* do nothing */ -} - export function asyncThrottle>( func: (...args: TArgs) => Promise, { interval = 1000, onError = noop }: AsyncThrottleOptions = {}, diff --git a/packages/query-async-storage-persister/src/index.ts b/packages/query-async-storage-persister/src/index.ts index 86a11167da..5dd961aa55 100644 --- a/packages/query-async-storage-persister/src/index.ts +++ b/packages/query-async-storage-persister/src/index.ts @@ -1,3 +1,4 @@ +import { noop } from '../../query-core/src/utils' import { asyncThrottle } from './asyncThrottle' import type { AsyncStorage, @@ -99,5 +100,3 @@ export const createAsyncStoragePersister = ({ removeClient: noop, } } - -function noop() {} diff --git a/packages/query-sync-storage-persister/src/index.ts b/packages/query-sync-storage-persister/src/index.ts index 61d9499430..3c2c75a70d 100644 --- a/packages/query-sync-storage-persister/src/index.ts +++ b/packages/query-sync-storage-persister/src/index.ts @@ -1,3 +1,4 @@ +import { noop } from '../../query-core/src/utils' import type { PersistRetryer, PersistedClient, @@ -108,5 +109,3 @@ function throttle>( } } } - -function noop() {} diff --git a/packages/react-query/src/useMutation.ts b/packages/react-query/src/useMutation.ts index deb4dd2580..355c57b500 100644 --- a/packages/react-query/src/useMutation.ts +++ b/packages/react-query/src/useMutation.ts @@ -1,6 +1,7 @@ 'use client' import * as React from 'react' import { MutationObserver, notifyManager } from '@tanstack/query-core' +import { noop } from '../../query-core/src/utils' import { useQueryClient } from './QueryClientProvider' import { shouldThrowError } from './utils' import type { @@ -63,5 +64,3 @@ export function useMutation< return { ...result, mutate, mutateAsync: result.mutate } } - -function noop() {} diff --git a/packages/solid-query/src/createMutation.ts b/packages/solid-query/src/createMutation.ts index 37bf04091c..e885f1a0cc 100644 --- a/packages/solid-query/src/createMutation.ts +++ b/packages/solid-query/src/createMutation.ts @@ -1,6 +1,7 @@ import { MutationObserver } from '@tanstack/query-core' import { createComputed, createMemo, on, onCleanup } from 'solid-js' import { createStore } from 'solid-js/store' +import { noop } from '../../query-core/src/utils' import { useQueryClient } from './QueryClientProvider' import { shouldThrowError } from './utils' import type { DefaultError } from '@tanstack/query-core' @@ -74,5 +75,3 @@ export function createMutation< return state } - -function noop() {} diff --git a/packages/svelte-query/src/createMutation.ts b/packages/svelte-query/src/createMutation.ts index 99fcf21117..071f0f8885 100644 --- a/packages/svelte-query/src/createMutation.ts +++ b/packages/svelte-query/src/createMutation.ts @@ -1,5 +1,6 @@ import { derived, get, readable } from 'svelte/store' import { MutationObserver, notifyManager } from '@tanstack/query-core' +import { noop } from '../../query-core/src/utils' import { useQueryClient } from './useQueryClient' import { isSvelteStore } from './utils' import type { @@ -47,5 +48,3 @@ export function createMutation< return { subscribe } } - -function noop() {} From 8e26b7b15bdda21601d2a00f5ad42784be566a4e Mon Sep 17 00:00:00 2001 From: Saul Lee Date: Sat, 24 Feb 2024 19:58:29 +0900 Subject: [PATCH 2/3] Revert "refactor(*): Import noop function from utils" This reverts commit c76f36fe941ab11538482f935e1bc591bfd00640. --- packages/angular-query-experimental/src/inject-mutation.ts | 3 ++- packages/query-async-storage-persister/src/asyncThrottle.ts | 6 ++++-- packages/query-async-storage-persister/src/index.ts | 3 ++- packages/query-sync-storage-persister/src/index.ts | 3 ++- packages/react-query/src/useMutation.ts | 3 ++- packages/solid-query/src/createMutation.ts | 3 ++- packages/svelte-query/src/createMutation.ts | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/angular-query-experimental/src/inject-mutation.ts b/packages/angular-query-experimental/src/inject-mutation.ts index 5943351506..41e47411b2 100644 --- a/packages/angular-query-experimental/src/inject-mutation.ts +++ b/packages/angular-query-experimental/src/inject-mutation.ts @@ -1,6 +1,5 @@ import { DestroyRef, computed, effect, inject, signal } from '@angular/core' import { MutationObserver, notifyManager } from '@tanstack/query-core' -import { noop } from '../../query-core/src/utils' import { assertInjector } from './util/assert-injector/assert-injector' import { signalProxy } from './signal-proxy' import { injectQueryClient } from './inject-query-client' @@ -65,3 +64,5 @@ export function injectMutation< > }) } + +function noop() {} diff --git a/packages/query-async-storage-persister/src/asyncThrottle.ts b/packages/query-async-storage-persister/src/asyncThrottle.ts index c295c5eb34..8f5157d56e 100644 --- a/packages/query-async-storage-persister/src/asyncThrottle.ts +++ b/packages/query-async-storage-persister/src/asyncThrottle.ts @@ -1,10 +1,12 @@ -import { noop } from '../../query-core/src/utils' - export interface AsyncThrottleOptions { interval?: number onError?: (error: unknown) => void } +const noop = () => { + /* do nothing */ +} + export function asyncThrottle>( func: (...args: TArgs) => Promise, { interval = 1000, onError = noop }: AsyncThrottleOptions = {}, diff --git a/packages/query-async-storage-persister/src/index.ts b/packages/query-async-storage-persister/src/index.ts index 5dd961aa55..86a11167da 100644 --- a/packages/query-async-storage-persister/src/index.ts +++ b/packages/query-async-storage-persister/src/index.ts @@ -1,4 +1,3 @@ -import { noop } from '../../query-core/src/utils' import { asyncThrottle } from './asyncThrottle' import type { AsyncStorage, @@ -100,3 +99,5 @@ export const createAsyncStoragePersister = ({ removeClient: noop, } } + +function noop() {} diff --git a/packages/query-sync-storage-persister/src/index.ts b/packages/query-sync-storage-persister/src/index.ts index 3c2c75a70d..61d9499430 100644 --- a/packages/query-sync-storage-persister/src/index.ts +++ b/packages/query-sync-storage-persister/src/index.ts @@ -1,4 +1,3 @@ -import { noop } from '../../query-core/src/utils' import type { PersistRetryer, PersistedClient, @@ -109,3 +108,5 @@ function throttle>( } } } + +function noop() {} diff --git a/packages/react-query/src/useMutation.ts b/packages/react-query/src/useMutation.ts index 355c57b500..deb4dd2580 100644 --- a/packages/react-query/src/useMutation.ts +++ b/packages/react-query/src/useMutation.ts @@ -1,7 +1,6 @@ 'use client' import * as React from 'react' import { MutationObserver, notifyManager } from '@tanstack/query-core' -import { noop } from '../../query-core/src/utils' import { useQueryClient } from './QueryClientProvider' import { shouldThrowError } from './utils' import type { @@ -64,3 +63,5 @@ export function useMutation< return { ...result, mutate, mutateAsync: result.mutate } } + +function noop() {} diff --git a/packages/solid-query/src/createMutation.ts b/packages/solid-query/src/createMutation.ts index e885f1a0cc..37bf04091c 100644 --- a/packages/solid-query/src/createMutation.ts +++ b/packages/solid-query/src/createMutation.ts @@ -1,7 +1,6 @@ import { MutationObserver } from '@tanstack/query-core' import { createComputed, createMemo, on, onCleanup } from 'solid-js' import { createStore } from 'solid-js/store' -import { noop } from '../../query-core/src/utils' import { useQueryClient } from './QueryClientProvider' import { shouldThrowError } from './utils' import type { DefaultError } from '@tanstack/query-core' @@ -75,3 +74,5 @@ export function createMutation< return state } + +function noop() {} diff --git a/packages/svelte-query/src/createMutation.ts b/packages/svelte-query/src/createMutation.ts index 071f0f8885..99fcf21117 100644 --- a/packages/svelte-query/src/createMutation.ts +++ b/packages/svelte-query/src/createMutation.ts @@ -1,6 +1,5 @@ import { derived, get, readable } from 'svelte/store' import { MutationObserver, notifyManager } from '@tanstack/query-core' -import { noop } from '../../query-core/src/utils' import { useQueryClient } from './useQueryClient' import { isSvelteStore } from './utils' import type { @@ -48,3 +47,5 @@ export function createMutation< return { subscribe } } + +function noop() {} From 7fae5ef909f729ba7a5c0837300ba0ed04d371ee Mon Sep 17 00:00:00 2001 From: Saul Lee Date: Sat, 24 Feb 2024 20:17:14 +0900 Subject: [PATCH 3/3] refactor(*): Add noop function in each package --- packages/angular-query-experimental/src/inject-mutation.ts | 3 +-- packages/angular-query-experimental/src/util/index.ts | 1 + packages/query-async-storage-persister/src/asyncThrottle.ts | 6 ++---- packages/query-async-storage-persister/src/index.ts | 3 +-- packages/query-async-storage-persister/src/utils.ts | 1 + packages/query-sync-storage-persister/src/index.ts | 3 +-- packages/query-sync-storage-persister/src/utils.ts | 1 + packages/react-query/src/useMutation.ts | 4 +--- packages/react-query/src/utils.ts | 2 ++ packages/solid-query/src/createMutation.ts | 4 +--- packages/solid-query/src/utils.ts | 2 ++ packages/svelte-query/src/createMutation.ts | 4 +--- packages/svelte-query/src/utils.ts | 2 ++ 13 files changed, 17 insertions(+), 19 deletions(-) create mode 100644 packages/angular-query-experimental/src/util/index.ts create mode 100644 packages/query-async-storage-persister/src/utils.ts create mode 100644 packages/query-sync-storage-persister/src/utils.ts diff --git a/packages/angular-query-experimental/src/inject-mutation.ts b/packages/angular-query-experimental/src/inject-mutation.ts index 41e47411b2..f4e2334013 100644 --- a/packages/angular-query-experimental/src/inject-mutation.ts +++ b/packages/angular-query-experimental/src/inject-mutation.ts @@ -3,6 +3,7 @@ import { MutationObserver, notifyManager } from '@tanstack/query-core' import { assertInjector } from './util/assert-injector/assert-injector' import { signalProxy } from './signal-proxy' import { injectQueryClient } from './inject-query-client' +import { noop } from './util' import type { DefaultError, QueryClient } from '@tanstack/query-core' import type { Injector } from '@angular/core' @@ -64,5 +65,3 @@ export function injectMutation< > }) } - -function noop() {} diff --git a/packages/angular-query-experimental/src/util/index.ts b/packages/angular-query-experimental/src/util/index.ts new file mode 100644 index 0000000000..177804c7ab --- /dev/null +++ b/packages/angular-query-experimental/src/util/index.ts @@ -0,0 +1 @@ +export function noop() {} diff --git a/packages/query-async-storage-persister/src/asyncThrottle.ts b/packages/query-async-storage-persister/src/asyncThrottle.ts index 8f5157d56e..835c33dfa4 100644 --- a/packages/query-async-storage-persister/src/asyncThrottle.ts +++ b/packages/query-async-storage-persister/src/asyncThrottle.ts @@ -1,12 +1,10 @@ +import { noop } from './utils' + export interface AsyncThrottleOptions { interval?: number onError?: (error: unknown) => void } -const noop = () => { - /* do nothing */ -} - export function asyncThrottle>( func: (...args: TArgs) => Promise, { interval = 1000, onError = noop }: AsyncThrottleOptions = {}, diff --git a/packages/query-async-storage-persister/src/index.ts b/packages/query-async-storage-persister/src/index.ts index 86a11167da..c280294dde 100644 --- a/packages/query-async-storage-persister/src/index.ts +++ b/packages/query-async-storage-persister/src/index.ts @@ -1,4 +1,5 @@ import { asyncThrottle } from './asyncThrottle' +import { noop } from './utils' import type { AsyncStorage, MaybePromise, @@ -99,5 +100,3 @@ export const createAsyncStoragePersister = ({ removeClient: noop, } } - -function noop() {} diff --git a/packages/query-async-storage-persister/src/utils.ts b/packages/query-async-storage-persister/src/utils.ts new file mode 100644 index 0000000000..177804c7ab --- /dev/null +++ b/packages/query-async-storage-persister/src/utils.ts @@ -0,0 +1 @@ +export function noop() {} diff --git a/packages/query-sync-storage-persister/src/index.ts b/packages/query-sync-storage-persister/src/index.ts index 61d9499430..9601fd4bad 100644 --- a/packages/query-sync-storage-persister/src/index.ts +++ b/packages/query-sync-storage-persister/src/index.ts @@ -1,3 +1,4 @@ +import { noop } from './utils' import type { PersistRetryer, PersistedClient, @@ -108,5 +109,3 @@ function throttle>( } } } - -function noop() {} diff --git a/packages/query-sync-storage-persister/src/utils.ts b/packages/query-sync-storage-persister/src/utils.ts new file mode 100644 index 0000000000..177804c7ab --- /dev/null +++ b/packages/query-sync-storage-persister/src/utils.ts @@ -0,0 +1 @@ +export function noop() {} diff --git a/packages/react-query/src/useMutation.ts b/packages/react-query/src/useMutation.ts index deb4dd2580..34edd450a2 100644 --- a/packages/react-query/src/useMutation.ts +++ b/packages/react-query/src/useMutation.ts @@ -2,7 +2,7 @@ import * as React from 'react' import { MutationObserver, notifyManager } from '@tanstack/query-core' import { useQueryClient } from './QueryClientProvider' -import { shouldThrowError } from './utils' +import { noop, shouldThrowError } from './utils' import type { UseMutateFunction, UseMutationOptions, @@ -63,5 +63,3 @@ export function useMutation< return { ...result, mutate, mutateAsync: result.mutate } } - -function noop() {} diff --git a/packages/react-query/src/utils.ts b/packages/react-query/src/utils.ts index b3a928ff6b..d07a9316fe 100644 --- a/packages/react-query/src/utils.ts +++ b/packages/react-query/src/utils.ts @@ -9,3 +9,5 @@ export function shouldThrowError) => boolean>( return !!throwError } + +export function noop() {} diff --git a/packages/solid-query/src/createMutation.ts b/packages/solid-query/src/createMutation.ts index 37bf04091c..39c56ff2e3 100644 --- a/packages/solid-query/src/createMutation.ts +++ b/packages/solid-query/src/createMutation.ts @@ -2,7 +2,7 @@ import { MutationObserver } from '@tanstack/query-core' import { createComputed, createMemo, on, onCleanup } from 'solid-js' import { createStore } from 'solid-js/store' import { useQueryClient } from './QueryClientProvider' -import { shouldThrowError } from './utils' +import { noop, shouldThrowError } from './utils' import type { DefaultError } from '@tanstack/query-core' import type { QueryClient } from './QueryClient' import type { @@ -74,5 +74,3 @@ export function createMutation< return state } - -function noop() {} diff --git a/packages/solid-query/src/utils.ts b/packages/solid-query/src/utils.ts index b3a928ff6b..d07a9316fe 100644 --- a/packages/solid-query/src/utils.ts +++ b/packages/solid-query/src/utils.ts @@ -9,3 +9,5 @@ export function shouldThrowError) => boolean>( return !!throwError } + +export function noop() {} diff --git a/packages/svelte-query/src/createMutation.ts b/packages/svelte-query/src/createMutation.ts index 99fcf21117..5997d8b2f0 100644 --- a/packages/svelte-query/src/createMutation.ts +++ b/packages/svelte-query/src/createMutation.ts @@ -1,7 +1,7 @@ import { derived, get, readable } from 'svelte/store' import { MutationObserver, notifyManager } from '@tanstack/query-core' import { useQueryClient } from './useQueryClient' -import { isSvelteStore } from './utils' +import { isSvelteStore, noop } from './utils' import type { CreateMutateFunction, CreateMutationOptions, @@ -47,5 +47,3 @@ export function createMutation< return { subscribe } } - -function noop() {} diff --git a/packages/svelte-query/src/utils.ts b/packages/svelte-query/src/utils.ts index eb86225694..617144fae0 100644 --- a/packages/svelte-query/src/utils.ts +++ b/packages/svelte-query/src/utils.ts @@ -6,3 +6,5 @@ export function isSvelteStore( ): obj is Readable { return 'subscribe' in obj && typeof obj.subscribe === 'function' } + +export function noop() {}