debounce method
Defines an explicit time-stabilized debounce Effect attached to this node.
Delays trigger execution until duration passes with no new mutations on this node.
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 execution limit before early teardown.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 unary debounce Effect attached to this node.
Examples
final query = blooming('');
final effect = query.bloom.effect.debounce(
const Duration(milliseconds: 300),
() => apiService.search(untracked(query.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.unary(
_target,
duration,
action,
guard: guard,
leading: leading,
trailing: trailing,
take: take,
onUncaughtError: onUncaughtError,
);