make disposal non-manual

This commit is contained in:
krawieck 2020-09-24 16:26:24 +02:00
parent a825a57840
commit c2f30665ec
2 changed files with 2 additions and 4 deletions

View File

@ -8,7 +8,6 @@ import 'ref.dart';
class Debounce { class Debounce {
final bool loading; final bool loading;
final void Function() callback; final void Function() callback;
final void Function() dispose;
void call() => callback(); void call() => callback();
@ -17,7 +16,6 @@ class Debounce {
const Debounce({ const Debounce({
@required this.loading, @required this.loading,
@required this.callback, @required this.callback,
@required this.dispose,
}); });
} }
@ -35,6 +33,8 @@ Debounce useDebounce(
loading.value = false; loading.value = false;
} }
useEffect(() => () => timerHandle.current?.cancel(), []);
start() { start() {
timerHandle.current = Timer(delayDuration, () async { timerHandle.current = Timer(delayDuration, () async {
loading.value = true; loading.value = true;
@ -49,6 +49,5 @@ Debounce useDebounce(
cancel(); cancel();
start(); start();
}, },
dispose: cancel,
); );
} }

View File

@ -44,7 +44,6 @@ class AddInstancePage extends HookWidget {
instanceController.addListener(debounce); instanceController.addListener(debounce);
return () { return () {
debounce.dispose();
instanceController.removeListener(debounce); instanceController.removeListener(debounce);
}; };
}, []); }, []);