fn
watchPausable
v0.0.14testeddemoA watch whose execution can be paused and resumed on demand via a pausable event filter.
Example
ts
const count = ref(0);
const { pause, resume, isActive } = watchPausable(count, (value) => {
console.log('changed to', value);
});
pause();
count.value++; // callback not called
resume();
count.value++; // callback calledDemo
Loading demo…
Signatures
ts
export function watchPausable<T extends Readonly<MultiWatchSources>, Immediate extends Readonly<boolean> = false>(
sources: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: UseWatchPausableOptions<Immediate>,
): UseWatchPausableReturn;ts
export function watchPausable<T, Immediate extends Readonly<boolean> = false>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: UseWatchPausableOptions<Immediate>,
): UseWatchPausableReturn;ts
export function watchPausable<T extends object, Immediate extends Readonly<boolean> = false>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: UseWatchPausableOptions<Immediate>,
): UseWatchPausableReturn;Type Parameters
Immediateextends Readonly<boolean>= falseParameters
| Parameter | Type | Description |
|---|---|---|
source | WatchSource<unknown> | MultiWatchSources | object | The watch source (ref, getter, reactive object, or an array of sources) |
cb | AnyFunction | The callback invoked when an active source changes |
options? | UseWatchPausableOptions<Immediate> | Watch options plus eventFilter and initialState |
Returns
UseWatchPausableReturn{ stop, pause, resume, isActive }| Property | Type | Description |
|---|---|---|
isActive | Readonly<Ref<boolean>> | Whether the watcher is currently active. While false, source changes are
ignored and the callback is not invoked. |
pause | () => void | Pause the watcher. Changes to the source are ignored until resume. |
resume | () => void | Resume the watcher so it reacts to source changes again. |
stop | WatchStopHandle | Stop the watcher entirely. It cannot be restarted afterwards. |