debounce method

BlocDebounceCallback<BlocEvent> debounce(
  1. BlocDebounceCallback<BlocEvent> function, {
  2. Duration delay = const Duration(milliseconds: 300),
})
inherited

Creates a debounced function that only invokes function after a delay.

For example:

 final debounced = debounce(() {
     // heavy stuff
 });

Implementation

BlocDebounceCallback debounce(
  BlocDebounceCallback function, {
  Duration delay = const Duration(milliseconds: 300),
}) {
  final debouncer =
      PublishSubject<Tuple2<Function, Map<dynamic, dynamic>?>>();
  publishers.add(debouncer);

  subxList.add(
    debouncer.debounceTime(delay).listen(
      (Tuple2<Function, Map<dynamic, dynamic>?> tuple) {
        tuple.item1(tuple.item2);
      },
    ),
  );

  return ([Map<dynamic, dynamic>? extras]) {
    final tuple = Tuple2<Function, Map<dynamic, dynamic>?>(function, extras);
    debouncer.add(tuple);
  };
}