debounce method
Defines an explicit time-stabilized debounce Effect attached to the scoped targets.
Delays executing action until invalidation bursts across all targets have ceased for at least duration.
duration: The silence window duration required before executingaction.action: The untracked callback to execute when the debounce window settles.guard: Optional boolean predicate gating execution.leading: Whether to execute immediately on first mutation. Defaults tofalse.trailing: Whether to execute on trailing edge after silence elapses. Defaults totrue.take: Optional maximum number of times this effect may execute.onUncaughtError: Optional error recovery handler.
Requires:
- At least one of
leadingortrailingmust betrue. - If
takeis provided, it must be greater than or equal to0.
Ensures:
- Returns a debounce Effect attached to the scoped targets.
Examples
final effect = (filter.bloom, sort.bloom).effect.debounce(
const Duration(milliseconds: 300),
() => fetchFiltered(untracked(filter.bloom), untracked(sort.bloom)),
);
Implementation
@pragma('vm:prefer-inline')
Effect debounce(
Duration duration,
void Function() action, {
bool Function()? guard,
bool leading = false,
bool trailing = true,
int? take,
void Function(Object error, StackTrace stackTrace)? onUncaughtError,
}) =>
Effect.debounce(
_targets,
duration,
action,
guard: guard,
leading: leading,
trailing: trailing,
take: take,
onUncaughtError: onUncaughtError,
);