EffectImpl.lazy constructor

EffectImpl.lazy(
  1. void fn(), {
  2. JoltDebugFn? onDebug,
})

Creates a new effect that runs immediately upon creation.

This factory method is a convenience constructor for creating an effect with lazy set to true. The effect will execute once immediately when created, then automatically re-run whenever its reactive dependencies change.

Parameters:

  • fn: The effect function to execute
  • onDebug: Optional debug callback for reactive system debugging

Returns: A new Effect instance that executes immediately

Example:

final signal = Signal(10);
final values = <int>[];

Effect.lazy(() {
  values.add(signal.value);
});

// Effect executed immediately with value 10
expect(values, equals([10]));

signal.value = 20; // Effect runs again
expect(values, equals([10, 20]));

Implementation

factory EffectImpl.lazy(void Function() fn, {JoltDebugFn? onDebug}) {
  return EffectImpl(fn, lazy: true, onDebug: onDebug);
}