debounceEvent method

BlocEventCallback<FastAppLoaderBlocEvent> debounceEvent(
  1. BlocEventCallback<FastAppLoaderBlocEvent> function, {
  2. Duration delay = const Duration(milliseconds: 300),
})
inherited

Debounces an event. The function will not be invoked until delay.

For example:

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

Implementation

BlocEventCallback<E> debounceEvent(
  BlocEventCallback<E> function, {
  Duration delay = const Duration(milliseconds: 300),
}) {
  final debouncer = PublishSubject<Tuple2<BlocEventCallback<E>, E>>();
  publishers.add(debouncer);

  subxList.add(
    debouncer
        .debounceTime(delay)
        .listen((Tuple2<BlocEventCallback<E>, E> tuple) {
      tuple.item1(tuple.item2);
    }),
  );

  return (E event) {
    final tuple = Tuple2<BlocEventCallback<E>, E>(function, event);
    debouncer.add(tuple);
  };
}