4 ms·
> How does effect knows that it needs to call this lambda whenever parity gets changed? The call `parity.get()` will register a dependency on the function that
by mondrian 3y ago
> How does effect knows that it needs to call this lambda whenever parity gets changed?
The call `parity.get()` will register a dependency on the function that is passed to `effect()`. When `parity` is updated, the function is called.
> Will it call this lambda on any signal change?
Only when a dependent signal changes.
In this case, `parity` depends on `isEven` and `isEven` depends on `counter`. So when `counter` is updated, that whole dependency chain is invalidated leading to `parity` getting invalidated, and that callback re-running.
- posix86 3y agoThis works well until you accidentally have an if/else branch, then you get hard to track bugs (halting problem in the general case). I'm guessing this is why they don't propose to add this function to the standard: That fact makes it not very pretty.