DebouncedEventListener<T> constructor

DebouncedEventListener<T>(
  1. EventCallback<T> onEvent, {
  2. Duration duration = const Duration(seconds: 1),
})

Used by EventRule for triggering onEvent callback.

A type of EventListener which delays its calls to prevent frequent calls.

Example

final event1 = Event<int>("int");

EventRule<int>(event1, targets: [

  // On Receiving `event1` call `onEvent`
  // with `payload` of type [int]
  DebouncedEventListener(
    (payload) {
      print("integer event: $payload");
    },
    duration: const Duration(seconds: 3),
  ),
]);


....

// Release Event
EventBus.emit(event1.createPayload(100)) // nothing happens
EventBus.emit(event1.createPayload(200)) // nothing happens
EventBus.emit(event1.createPayload(400)) // prints "integer event: 400" after 3 second


See Also:

duration : debounce time default: 1 second

Implementation

DebouncedEventListener(
  EventCallback<T> onEvent, {
  this.duration = const Duration(seconds: 1),
}) : super(onEvent);