Effect.unary constructor

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

Creates an optimized unary manifest Effect attached strictly to a single explicit target.

Provides zero-allocation fast-path dispatch by bypassing intermediate List allocations and linking directly via a specialized unary edge terminal.

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

  • Executes action in an untracked environment when target mutates.

  • 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 target (Early Teardown).

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

  • target: The single Bloom node to monitor.

  • action: The untracked callback to invoke upon mutation.

  • guard: Optional boolean predicate gating execution.

  • take: Optional limit on execution count before automatic deactivation.

  • onUncaughtError: Optional error recovery handler.

Requires:

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

Ensures:

  • Returns an optimized unary manifest Effect bound to target.

Throws:

Examples

final query = blooming('');
final e = Effect.unary(query.bloom, () {
  print('Query changed to: ${untracked(query.bloom)}');
});

Implementation

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