make disposal non-manual
This commit is contained in:
parent
a825a57840
commit
c2f30665ec
|
@ -8,7 +8,6 @@ import 'ref.dart';
|
|||
class Debounce {
|
||||
final bool loading;
|
||||
final void Function() callback;
|
||||
final void Function() dispose;
|
||||
|
||||
void call() => callback();
|
||||
|
||||
|
@ -17,7 +16,6 @@ class Debounce {
|
|||
const Debounce({
|
||||
@required this.loading,
|
||||
@required this.callback,
|
||||
@required this.dispose,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -35,6 +33,8 @@ Debounce useDebounce(
|
|||
loading.value = false;
|
||||
}
|
||||
|
||||
useEffect(() => () => timerHandle.current?.cancel(), []);
|
||||
|
||||
start() {
|
||||
timerHandle.current = Timer(delayDuration, () async {
|
||||
loading.value = true;
|
||||
|
@ -49,6 +49,5 @@ Debounce useDebounce(
|
|||
cancel();
|
||||
start();
|
||||
},
|
||||
dispose: cancel,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ class AddInstancePage extends HookWidget {
|
|||
instanceController.addListener(debounce);
|
||||
|
||||
return () {
|
||||
debounce.dispose();
|
||||
instanceController.removeListener(debounce);
|
||||
};
|
||||
}, []);
|
||||
|
|
Loading…
Reference in New Issue