bloc_event_transformers 1.0.2+1 bloc_event_transformers: ^1.0.2+1 copied to clipboard
Configurable transformers for your bloc (bloclibrary.dev) events. Throttle, debounce, skip, and delay with ease.
Throttle #
Emits an Event, then ignores subsequent events for a duration, then repeats this process.
If leading is true, then the first event in each window is emitted.
If trailing is true, then the last event is emitted instead.
on<ExampleEvent>(
_handler,
transformer: throttle(const Duration(seconds: 5))
);
Debounce #
Event transformer that will only emit items from the source sequence whenever the time span defined by [duration] passes, without the source sequence emitting another item.
This time span start after the last debounced event was emitted. debounce filters out items obtained events that are rapidly followed by another emitted event.
on<ExampleEvent>(
_handleEvent,
transformer: debounce(const Duration(seconds: 1)),
);
Skip #
Skips the first [count] events.
on<ExampleEvent>(
_handleEvent,
transformer: skip(10),
);
Delay #
The delay() transformer is pausing adding events for a particular increment of time (that you specify) before emitting each of the events.
This has the effect of shifting the entire sequence of events added to the bloc forward in time by that specified increment.
on<ExampleEvent>(
_handleEvent,
transformer: delay(const Duration(seconds: 1)),
);