fix debounce sideeffect to dispose debounce
This commit is contained in:
parent
80a06bf14b
commit
6c8251b7aa
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,10 @@ class AddInstancePage extends HookWidget {
|
|||
useEffect(() {
|
||||
instanceController.addListener(debounce);
|
||||
|
||||
return () => instanceController.removeListener(debounce);
|
||||
return () {
|
||||
debounce.dispose();
|
||||
instanceController.removeListener(debounce);
|
||||
};
|
||||
}, []);
|
||||
|
||||
handleOnAdd() async {
|
||||
|
|
Loading…
Reference in New Issue