Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jifalops/debounce_throttle

An observer, debouncer, and throttle that works with Futures, Streams, and callbacks.
https://github.com/jifalops/debounce_throttle

Last synced: about 2 months ago
JSON representation

An observer, debouncer, and throttle that works with Futures, Streams, and callbacks.

Awesome Lists containing this project

README

        

# debounce_throttle

A debouncer and throttle that works with `Future`, `Stream`, and callbacks.

Class | Purpose
-|-
`Debouncer` | Wait for changes to stop before notifying.
`Throttle` | Notifies once per `Duration` for a value that keeps changing.

## Usage

```dart
final debouncer = Debouncer(Duration(milliseconds: 200));

// Run a search whenever the user pauses while typing.
textEditingController.addListener(() => debouncer.value = textEditingController.text);
debouncer.values.listen((search) => submitSearch(search));

final throttle = Throttle(Duration(milliseconds: 100));

// Limit being notified of continuous sensor data.
sensor.addListener(throttle.setValue);
throttle.values.listen((data) => print('$data'));
```

## `example/main.dart` output

```
Tick : ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Changed : ----------- - -- - - - -- - - - - - - - --- - - - - - - - - - - - -- - - - - - - -- - -- --- - - - - - - - - -
Debounced: D D D D D D D D D D D D D D D D D D D D D D D D D D D
Throttled: T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T
```