Effect constructor

Effect(
  1. Iterable<Bloom> targets,
  2. void action(), {
  3. bool guard()?,
  4. int? take,
  5. void onUncaughtError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Creates a manifest Effect attached strictly to explicit targets.

  • Skips initial evaluation (0 runs upon construction/mount).

  • Executes action in an untracked environment when any of targets mutate.

  • If guard is provided and returns false, execution is skipped and take tickets are preserved.

  • If take is provided, executes at most take times and then automatically deactivates and detaches from upstream targets (Early Teardown).

  • If onUncaughtError is provided, it is invoked when an uncaught exception is thrown in action or guard.

  • targets: The reactive Bloom nodes to monitor for mutations.

  • action: The untracked callback to invoke upon mutation.

  • guard: Optional boolean predicate gating execution and preserving tickets when returning false.

  • take: Optional limit on execution count before automatic deactivation. Must be non-negative.

  • onUncaughtError: Optional error recovery handler invoked on uncaught exceptions.

Requires:

  • If take is provided, it must be greater than or equal to 0.

Ensures:

  • Returns a manifest Effect bound to targets.

Throws:

Examples

final counter = blooming(0);
final e = Effect([counter.bloom], () {
  print('Counter mutated to: ${untracked(counter.bloom)}');
});

Implementation

@pragma('vm:prefer-inline')
factory Effect(
  Iterable<Bloom> targets,
  void Function() action, {
  bool Function()? guard,
  int? take,
  void Function(Object error, StackTrace stackTrace)? onUncaughtError,
}) =>
    _ManifestEffect(
      targets,
      action,
      guard: guard,
      take: take,
      onUncaughtError: onUncaughtError,
    );