fix debounce sideeffect to dispose debounce

This commit is contained in:
krawieck 2020-09-24 15:01:20 +02:00
parent 80a06bf14b
commit 6c8251b7aa
2 changed files with 15 additions and 6 deletions

View File

@ -8,12 +8,16 @@ import 'ref.dart';
class Debounce {
final bool loading;
final void Function() callback;
final void Function() dispose;
void call() => callback();
// void dispose() {}
const Debounce({
@required this.loading,
@required this.callback,
@required this.dispose,
});
}
@ -40,9 +44,11 @@ Debounce useDebounce(
}
return Debounce(
loading: loading.value,
callback: () {
cancel();
start();
});
loading: loading.value,
callback: () {
cancel();
start();
},
dispose: cancel,
);
}

View File

@ -42,7 +42,10 @@ class AddInstancePage extends HookWidget {
useEffect(() {
instanceController.addListener(debounce);
return () => instanceController.removeListener(debounce);
return () {
debounce.dispose();
instanceController.removeListener(debounce);
};
}, []);
handleOnAdd() async {