fn

watchIgnorable

v0.0.14testeddemo

Extended watch that exposes ignoreUpdates(fn) and ignorePrevAsyncUpdates() to suppress reactions to programmatic writes.

Example

ts
const count = ref(0);
const { ignoreUpdates } = watchIgnorable(count, value => console.log('changed', value));

count.value = 1;            // logs: changed 1
ignoreUpdates(() => {
  count.value = 2;          // does NOT log
});
count.value = 3;            // logs: changed 3

Demo

Loading demo…

Signatures

ts
export function watchIgnorable<T, Immediate extends Readonly<boolean> = false>(
  source: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options?: WatchWithFilterOptions<Immediate>,
): WatchIgnorableReturn;
ts
export function watchIgnorable<T extends Readonly<MultiWatchSources>, Immediate extends Readonly<boolean> = false>(
  sources: [...T],
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options?: WatchWithFilterOptions<Immediate>,
): WatchIgnorableReturn;
ts
export function watchIgnorable<T extends object, Immediate extends Readonly<boolean> = false>(
  source: T,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options?: WatchWithFilterOptions<Immediate>,
): WatchIgnorableReturn;

Type Parameters

Immediateextends Readonly<boolean>= false

Parameters

ParameterTypeDescription
sourceWatchSource<unknown> | MultiWatchSources | objectThe reactive source (ref, getter, reactive object, or array of sources) to watch
cbAnyFunctionInvoked with the new value, old value, and onCleanup when the source changes (unless ignored)
options?WatchWithFilterOptions<Immediate>Watch options (immediate, deep, flush) plus an optional eventFilter

Returns

WatchIgnorableReturn{ ignoreUpdates, ignorePrevAsyncUpdates, stop }
PropertyTypeDescription
ignoreUpdatesIgnoredUpdaterRun updater, suppressing the watch callback for any source writes it performs
ignorePrevAsyncUpdatesIgnoredPrevAsyncUpdatesIgnore the callback for source changes already queued before this call (async flush only)
stopWatchStopHandleStop the underlying watcher(s)