Skip to content

refactor(watch): replace WatchStopHandle with WatchHandle in watchAtMost, watchDebounced, watchIgnorable, watchTriggerable, and watchWithFilter for consistency and improved functionality #4852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
refactor: replace WatchStopHandle with WatchHandle in watchDebounced,…
… watchDeep, watchImmediate, watchOnce, and watchThrottled for consistency
  • Loading branch information
ArthurDarkstone committed Jul 4, 2025
commit 503916094bc35adc38223301b89258d2ebe1b35e
8 changes: 4 additions & 4 deletions packages/shared/watchDebounced/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MaybeRefOrGetter, WatchCallback, WatchHandle, WatchOptions, WatchSource, WatchStopHandle } from 'vue'
import type { MaybeRefOrGetter, WatchCallback, WatchHandle, WatchOptions, WatchSource } from 'vue'
import type { DebounceFilterOptions, MapOldSources, MapSources } from '../utils'
import { debounceFilter } from '../utils'
import { watchWithFilter } from '../watchWithFilter'
Expand All @@ -8,9 +8,9 @@ export interface WatchDebouncedOptions<Immediate> extends WatchOptions<Immediate
}

// overloads
export function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle
export function watchDebounced<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle
export function watchDebounced<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle
export function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchDebouncedOptions<Immediate>): WatchHandle
export function watchDebounced<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchHandle
export function watchDebounced<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchHandle

// implementation
export function watchDebounced<Immediate extends Readonly<boolean> = false>(
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/watchDeep/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue'
import type { WatchCallback, WatchHandle, WatchOptions, WatchSource } from 'vue'
import type { MapOldSources, MapSources } from '../utils/types'

import { watch } from 'vue'
Expand All @@ -11,13 +11,13 @@ export function watchDeep<
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
): WatchHandle

export function watchDeep<T, Immediate extends Readonly<boolean> = false>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
): WatchHandle

export function watchDeep<
T extends object,
Expand All @@ -26,7 +26,7 @@ export function watchDeep<
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: Omit<WatchOptions<Immediate>, 'deep'>
): WatchStopHandle
): WatchHandle

/**
* Shorthand for watching value with {deep: true}
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/watchImmediate/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue'
import type { WatchCallback, WatchHandle, WatchOptions, WatchSource } from 'vue'
import type { MapOldSources, MapSources } from '../utils/types'

import { watch } from 'vue'
Expand All @@ -8,19 +8,19 @@ export function watchImmediate<T extends Readonly<WatchSource<unknown>[]>>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>,
options?: Omit<WatchOptions<true>, 'immediate'>
): WatchStopHandle
): WatchHandle

export function watchImmediate<T>(
source: WatchSource<T>,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, 'immediate'>
): WatchStopHandle
): WatchHandle

export function watchImmediate<T extends object>(
source: T,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, 'immediate'>
): WatchStopHandle
): WatchHandle

/**
* Shorthand for watching value with {immediate: true}
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/watchOnce/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue'
import type { WatchCallback, WatchHandle, WatchOptions, WatchSource } from 'vue'
import type { MapOldSources, MapSources } from '../utils'
import { watch } from 'vue'

Expand All @@ -7,19 +7,19 @@ export function watchOnce<T extends Readonly<WatchSource<unknown>[]>>(
source: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>,
options?: Omit<WatchOptions<true>, 'once'>
): WatchStopHandle
): WatchHandle

export function watchOnce<T>(
source: WatchSource<T>,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, 'once'>
): WatchStopHandle
): WatchHandle

export function watchOnce<T extends object>(
source: T,
cb: WatchCallback<T, T | undefined>,
options?: Omit<WatchOptions<true>, 'once'>
): WatchStopHandle
): WatchHandle

/**
* Shorthand for watching value with { once: true }
Expand Down
10 changes: 5 additions & 5 deletions packages/shared/watchThrottled/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MaybeRefOrGetter, WatchCallback, WatchOptions, WatchSource, WatchStopHandle } from 'vue'
import type { MaybeRefOrGetter, WatchCallback, WatchHandle, WatchOptions, WatchSource } from 'vue'
import type { MapOldSources, MapSources } from '../utils'
import { throttleFilter } from '../utils'
import { watchWithFilter } from '../watchWithFilter'
Expand All @@ -10,16 +10,16 @@ export interface WatchThrottledOptions<Immediate> extends WatchOptions<Immediate
}

// overloads
export function watchThrottled<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle
export function watchThrottled<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle
export function watchThrottled<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle
export function watchThrottled<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchThrottledOptions<Immediate>): WatchHandle
export function watchThrottled<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchHandle
export function watchThrottled<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchHandle

// implementation
export function watchThrottled<Immediate extends Readonly<boolean> = false>(
source: any,
cb: any,
options: WatchThrottledOptions<Immediate> = {},
): WatchStopHandle {
): WatchHandle {
const {
throttle = 0,
trailing = true,
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy