Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/jifalops/debounce_throttle
- Owner: jifalops
- License: mit
- Created: 2019-07-19T20:34:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-05T03:16:45.000Z (almost 4 years ago)
- Last Synced: 2024-01-07T17:14:13.088Z (about 1 year ago)
- Language: Dart
- Size: 6.84 KB
- Stars: 16
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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
```