watch-source
Shared source and callback typing for the watch helpers (watchDebounced, watchThrottled, watchPausable, watchIgnorable, watchOnce, whenever). The helpers accept the same sources as Vue's watch: a ref, a getter, a reactive object, or a tuple of those. This module declares types only and contributes no runtime code.
| Package | @vizejs/composable/watch-source |
| Own the source | vize lib pull composable:watch-source |
| Runtime exports | — |
| Gzip budget | 256 B |
Usage
import type { WatchSourceInput, WatchSources, WatchSourceValue, WatchValue, WatchOldValue, WatchHelperCallback, WatchCleanupRegistrar } from "@vizejs/composable/watch-source";
Types
WatchSourceInput
A single source accepted by Vue's watch: ref, getter, or reactive object.
type WatchSourceInput = WatchSource<unknown> | object
WatchSources
Every source shape accepted by the watch helpers, including tuples.
type WatchSources = WatchSourceInput | readonly WatchSourceInput[]
WatchSourceValue
Value observed from a single source: the ref/getter value, or the reactive object itself.
type WatchSourceValue<Source> = Source extends WatchSource<infer Value> ? Value : Source extends object ? Source : never
WatchValue
Value delivered to a watch callback for WatchSources: a tuple source maps element-wise, any other source resolves through WatchSourceValue.
type WatchValue<Sources> = Sources extends readonly unknown[] ? { -readonly [Index in keyof Sources]: WatchSourceValue<Sources[Index]> } : WatchSourceValue<Sources>
WatchOldValue
Previous value delivered to a watch callback: undefined is added only when the watcher runs immediately (tuples get it per element, as in Vue).
type WatchOldValue<Sources, Immediate> = Immediate extends true ? Sources extends readonly unknown[] ? { -readonly [Index in keyof Sources]: WatchSourceValue<Sources[Index]> | undefined } : WatchSourceValue<Sources> | undefined : WatchValue<Sources>
WatchHelperCallback
Callback typed from its sources and the immediate flag.
type WatchHelperCallback<Sources, Immediate = false> = WatchCallback< WatchValue<Sources>, WatchOldValue<Sources, Immediate> >
WatchCleanupRegistrar
Cleanup registrar passed as the third argument of a watch callback.
type WatchCleanupRegistrar = Parameters<WatchCallback>[2]