EffectImpl.lazy constructor
EffectImpl.lazy(
- void fn(), {
- bool? detach,
- JoltDebugOption? debug,
Creates a new effect that does not run automatically upon creation.
This factory method is a convenience constructor for creating an effect
with lazy set to true. The effect will not execute until you call
run. After the first manual run, it will track dependencies and re-run
when they change.
Parameters:
fn: The effect function to executedetach: If true, the effect will not be bound to the current scopedebug: Optional debug options
Returns: A new Effect instance that starts in deferred mode
Example:
final signal = Signal(10);
final values = <int>[];
Effect.lazy(() {
values.add(signal.value);
});
// Effect has not run yet
expect(values, isEmpty);
effect.run(); // Start tracking and run once
expect(values, equals([10]));
signal.value = 20; // Effect runs again after tracking starts
expect(values, equals([10, 20]));
Implementation
factory EffectImpl.lazy(void Function() fn,
{bool? detach, JoltDebugOption? debug}) {
return EffectImpl(fn, lazy: true, detach: detach, debug: debug);
}