make disposal non-manual
This commit is contained in:
parent
a825a57840
commit
c2f30665ec
|
@ -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,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ class AddInstancePage extends HookWidget {
|
||||||
instanceController.addListener(debounce);
|
instanceController.addListener(debounce);
|
||||||
|
|
||||||
return () {
|
return () {
|
||||||
debounce.dispose();
|
|
||||||
instanceController.removeListener(debounce);
|
instanceController.removeListener(debounce);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
Loading…
Reference in New Issue