change `onDebounce` to `callback`

This commit is contained in:
krawieck 2020-09-22 13:50:54 +02:00
parent 15f408e8db
commit df4e1253b4
1 changed files with 3 additions and 5 deletions

View File

@ -9,9 +9,7 @@ class Debounce {
final bool loading; final bool loading;
final void Function() bounce; final void Function() bounce;
call() { void call() => bounce();
bounce();
}
const Debounce({ const Debounce({
@required this.loading, @required this.loading,
@ -23,7 +21,7 @@ class Debounce {
/// and loading is triggered after [delayDuration]. /// and loading is triggered after [delayDuration].
/// Everything can be reset with [.cancel()] /// Everything can be reset with [.cancel()]
Debounce useDebounce( Debounce useDebounce(
Future<Null> Function() onDebounce, [ Future<Null> Function() callback, [
Duration delayDuration = const Duration(milliseconds: 500), Duration delayDuration = const Duration(milliseconds: 500),
]) { ]) {
final loading = useState(false); final loading = useState(false);
@ -37,7 +35,7 @@ Debounce useDebounce(
start() { start() {
timerHandle.current = Timer(delayDuration, () async { timerHandle.current = Timer(delayDuration, () async {
loading.value = true; loading.value = true;
await onDebounce(); await callback();
cancel(); cancel();
}); });
} }