effect function

void effect(
  1. void sideEffect()
)

Create a side effect that runs whenever its dependencies update.

Declare a sideEffect that will re-run whenever any of its dependencies update their state. Any signals that are referenced within the effect will be automatically tracked without an explicit dependency List declared.

An effect must only be run once as it will automatically re-run by itself whenever any of its dependencies update. The sideEffect must not directly write to any of its dependencies to avoid an infinite loop; as a rule of thumb, a signal's getter and setter methods must not be used within the effect at the same time.

Implementation

void effect(void Function() sideEffect) {
  final (_, :push, :pull) = effects;

  push((_) => () => sideEffect());
  sideEffect();
  pull();
}