The predicate that should be evaluated.
The function to be called when the predicate evaluates to true.
Optional
options: { Optional options.
The number of milliseconds to wait before calling the function.
An AbortSignal to cancel the function call.
The number of milliseconds to wait before timing out.
A function that can be called to unsubscribe the callback function from changes in the tracked dependencies.
const a = atom(0, { name: "a" });
let foo = 0;
when(
() => a.value > 3,
() => {
foo++;
}
);
a.value = 2; // foo = 0
a.value = 3; // foo = 0
a.value = 4; // foo = 1
a.value = 5; // foo = 1
a.value = 3; // foo = 1
a.value = 4; // foo = 2
a.value = 5; // foo = 2
Automatically calls the given function whenever the given predicate evaluates to true.