fn
watchIgnorable
v0.0.15testeddemoExtended `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 | any | 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 }`