Effect constructor
Creates a manifest Effect attached strictly to explicit targets.
-
Skips initial evaluation (0 runs upon construction/mount).
-
Executes
actionin an untracked environment when any oftargetsmutate. -
If
guardis provided and returnsfalse, execution is skipped andtaketickets are preserved. -
If
takeis provided, executes at mosttaketimes and then automatically deactivates and detaches from upstream targets (Early Teardown). -
If
onUncaughtErroris provided, it is invoked when an uncaught exception is thrown inactionorguard. -
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 returningfalse. -
take: Optional limit on execution count before automatic deactivation. Must be non-negative. -
onUncaughtError: Optional error recovery handler invoked on uncaught exceptions.
Requires:
- If
takeis provided, it must be greater than or equal to0.
Ensures:
- Returns a manifest Effect bound to
targets.
Throws:
- RangeError if
takeis negative.
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,
);