DebouncedEventListener<T> constructor
DebouncedEventListener<T> (
- EventCallback<
T> onEvent, { - 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:
- EventListener : An EventListener which calls its onEvent.
- OneOffEventListener : An EventListener which only calls its onEvent one time.
duration
: debounce time default: 1 second
Implementation
DebouncedEventListener(
EventCallback<T> onEvent, {
this.duration = const Duration(seconds: 1),
}) : super(onEvent);