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 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 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 maximum number of times this effect may execute.
  • 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 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,
    );