fn
whenever
v0.0.14testeddemoShorthand for watching a source to be truthy. Behaves like watch, but the callback only fires when the resolved value is truthy.
Examples
ts
const ready = ref(false);
whenever(ready, () => console.log('ready!'));ts
whenever(() => count.value > 5, () => console.log('over five'), { once: true });Demo
Loading demo…
Signatures
ts
export function whenever<T>(source: WatchSource<T>, cb: WatchCallback<Truthy<T>, T | undefined>, options?: WheneverOptions<true>): WatchHandle;ts
export function whenever<T>(source: WatchSource<T>, cb: WatchCallback<Truthy<T>, T>, options?: WheneverOptions<false>): WatchHandle;Type Parameters
TParameters
| Parameter | Type | Description |
|---|---|---|
source | WatchSource<T> | The reactive source to watch |
cb | WatchCallback<Truthy<T>, T | undefined> | Invoked with the truthy value, previous value, and onCleanup |
options? | WheneverOptions | Watch options (immediate, deep, flush, once) |
Returns
WatchHandleA handle to stop watching