Handle pages with multiple debouncers

This commit is contained in:
Hillel Coren 2022-11-17 13:18:52 +02:00
parent e5fb62efc4
commit aa5f5dfcc6
5 changed files with 14 additions and 8 deletions

View File

@ -378,7 +378,7 @@ Middleware<AppState> _createPersistData(
}; };
} }
final _persistUIDebouncer = PersistUIDebouncer(); final _persistUIDebouncer = SimpleDebouncer();
Middleware<AppState> _createPersistUI(PersistenceRepository uiRepository) { Middleware<AppState> _createPersistUI(PersistenceRepository uiRepository) {
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) { return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
final action = dynamicAction as PersistUI; final action = dynamicAction as PersistUI;

View File

@ -51,9 +51,10 @@ class _DesignEditState extends State<DesignEdit>
static final GlobalKey<FormState> _formKey = static final GlobalKey<FormState> _formKey =
GlobalKey<FormState>(debugLabel: '_designEdit'); GlobalKey<FormState>(debugLabel: '_designEdit');
final _pdfDebouncer = Debouncer(milliseconds: kMillisecondsToDebounceSave);
final _debouncer = Debouncer(); final _debouncer = Debouncer();
final _htmlDebouncer = Debouncer(); final _pdfDebouncer =
SimpleDebouncer(milliseconds: kMillisecondsToDebounceSave);
final _htmlDebouncer = SimpleDebouncer();
final _nameController = TextEditingController(); final _nameController = TextEditingController();
final _htmlController = TextEditingController(); final _htmlController = TextEditingController();

View File

@ -1124,7 +1124,8 @@ class _PdfPreview extends StatefulWidget {
} }
class __PdfPreviewState extends State<_PdfPreview> { class __PdfPreviewState extends State<_PdfPreview> {
final _pdfDebouncer = Debouncer(milliseconds: kMillisecondsToDebounceSave); final _pdfDebouncer =
SimpleDebouncer(milliseconds: kMillisecondsToDebounceSave);
int _pageCount = 1; int _pageCount = 1;
int _currentPage = 1; int _currentPage = 1;

View File

@ -57,7 +57,7 @@ class _ClientPortalState extends State<ClientPortal>
bool _isCheckingSubdomain = false; bool _isCheckingSubdomain = false;
final _subdomainDebouncer = final _subdomainDebouncer =
Debouncer(milliseconds: kMillisecondsToDebounceSave); SimpleDebouncer(milliseconds: kMillisecondsToDebounceSave);
final _debouncer = Debouncer(); final _debouncer = Debouncer();
final _subdomainController = TextEditingController(); final _subdomainController = TextEditingController();

View File

@ -118,8 +118,12 @@ class Debouncer {
} }
} }
class PersistUIDebouncer { class SimpleDebouncer {
PersistUIDebouncer(); SimpleDebouncer({
this.milliseconds = kMillisecondsToDebounceWrite,
});
final int milliseconds;
static VoidCallback action; static VoidCallback action;
static Timer timer; static Timer timer;
@ -132,7 +136,7 @@ class PersistUIDebouncer {
Debouncer.action = action; Debouncer.action = action;
} }
timer = Timer(Duration(milliseconds: kMillisecondsToDebounceWrite), () { timer = Timer(Duration(milliseconds: milliseconds), () {
if (action != null) { if (action != null) {
action(); action();
} }