fn
watchIgnorable
v0.0.14testeddemoExtended 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 3Demo
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>= falseParameters
| Parameter | Type | Description |
|---|---|---|
source | WatchSource<unknown> | MultiWatchSources | object | The reactive source (ref, getter, reactive object, or array of sources) to watch |
cb | AnyFunction | Invoked 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 }| Property | Type | Description |
|---|---|---|
ignoreUpdates | IgnoredUpdater | Run updater, suppressing the watch callback for any source writes it performs |
ignorePrevAsyncUpdates | IgnoredPrevAsyncUpdates | Ignore the callback for source changes already queued before this call (async flush only) |
stop | WatchStopHandle | Stop the underlying watcher(s) |