watch-pausable
Watch sources like Vue's watch, with pause and resume.
| Package | @vizejs/composable/watch-pausable |
| Own the source | vize lib pull composable:watch-pausable |
| Runtime exports | watchPausable |
| Gzip budget | 512 B |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/composable
Import the entry directly. Call lifecycle-bound utilities inside <script setup> so cleanup follows the component scope; consult the runtime contract for this entry's SSR and hydration behavior.
import { watchPausable } from "@vizejs/composable/watch-pausable";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
watchPausable |
reactivity | experimental | safe | not-applicable | caller, reactive-scope | web, server, worker, native, desktop, terminal | — | — |
API
watchPausable
Watch sources like Vue's watch, with pause and resume. Unlike the pause() built into Vue 3.5 watch handles, which delivers one catch-up call on resume, changes made while paused are dropped: the callback only ever sees changes that happened while active. The old value passed after a resume is the value from the most recent change Vue observed, whether or not it was delivered. The watcher follows the owning reactive scope and is safe during server rendering.
function watchPausable< const Sources extends WatchSources, Immediate extends Readonly<boolean> = false, >( source: Sources, callback: WatchHelperCallback<Sources, Immediate>, options?: WatchPausableOptions<Immediate>, ): PausableWatchHandle
const { pause, resume } = watchPausable(form, persist, { deep: true });
pause();
form.name = "x"; // not persisted
resume();
watchPausable
function watchPausable( source: WatchSources, callback: WatchCallback<unknown, unknown>, options: WatchPausableOptions<boolean> = {}, ): PausableWatchHandle
Types
PausableWatchHandle
Controls returned by watchPausable.
| Member | Type | Description |
|---|---|---|
isActive |
Readonly<ShallowRef<boolean>> |
Whether changes are currently delivered to the callback. |
pause |
() => void |
Drop changes until PausableWatchHandle.resume. Idempotent. |
resume |
() => void |
Deliver changes again. Changes made while paused are not replayed. |
stop |
() => void |
Stop watching permanently. |
WatchPausableOptions
Options for watchPausable.
| Member | Type | Description |
|---|---|---|
initiallyPaused? |
boolean |
Start in the paused state. |