debounce method

Effect debounce(
  1. Duration duration,
  2. void action(), {
  3. bool guard()?,
  4. bool leading = false,
  5. bool trailing = true,
  6. int? take,
  7. void onUncaughtError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

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 executing action.
  • 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 to false.
  • trailing: Whether to execute on trailing edge after silence elapses. Defaults to true.
  • take: Optional execution limit before early teardown.
  • onUncaughtError: Optional error recovery handler.

Requires:

  • At least one of leading or trailing must be true.
  • If take is provided, it must be greater than or equal to 0.

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,
    );