watch-ignorable
Watch sources like Vue's watch, with a way to make changes the callback should not see.
| Package | @vizejs/composable/watch-ignorable |
| Own the source | vize lib pull composable:watch-ignorable |
| Runtime exports | watchIgnorable |
| Gzip budget | 768 B |
Usage
import { watchIgnorable } from "@vizejs/composable/watch-ignorable";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
watchIgnorable |
reactivity | experimental | safe | not-applicable | caller, reactive-scope | web, server, worker, native, desktop, terminal | — | — |
API
watchIgnorable
Watch sources like Vue's watch, with a way to make changes the callback should not see. Typical use is two-way syncing: writes performed inside ignoreUpdates (for example applying a server echo) do not bounce back. Works with every flush mode: for "pre"/"post", a synchronous side watcher counts changes so that a batch made only of ignored writes is skipped, while a batch that mixes ignored and regular writes is still delivered. Stops with the owning reactive scope; safe during server rendering.
function watchIgnorable< const Sources extends WatchSources, Immediate extends Readonly<boolean> = false, >( source: Sources, callback: WatchHelperCallback<Sources, Immediate>, options?: WatchOptions<Immediate>, ): IgnorableWatchHandle
const { ignoreUpdates } = watchIgnorable(draft, (value) => save(value));
ignoreUpdates(() => {
draft.value = fromServer; // not saved again
});
watchIgnorable
function watchIgnorable( source: WatchSources, callback: WatchCallback<unknown, unknown>, options: WatchOptions<boolean> = {}, ): IgnorableWatchHandle
Types
IgnorableWatchHandle
Controls returned by watchIgnorable.
| Member | Type | Description |
|---|---|---|
ignoreUpdates |
(updater: () => void) => void |
Run updater so that the source changes it makes synchronously do not trigger the callback. |
ignorePrevAsyncUpdates |
() => void |
Swallow the changes already queued for the next (non-sync) flush. A no-op for flush: "sync" watchers, which have nothing queued. |
stop |
() => void |
Stop watching permanently. |