chore(async-table): refactor

This commit is contained in:
Sarah Vaupel 2019-11-19 19:26:48 +01:00 committed by Gregor Kleen
parent 22b3780efd
commit bfd35dbc5c
2 changed files with 23 additions and 4 deletions

View File

@ -184,10 +184,28 @@ export class AsyncTable {
});
this._tableFilterInputs.input.forEach((input) => {
input.submitLockObserver = new MutationObserver((mutations, observer) => {
for (const mutation of mutations) {
// if the submit lock has been released, trigger an update and disconnect this observer
if (mutation.oldValue === 'true' && input.getAttribute(ATTR_SUBMIT_LOCKED) === 'false') {
this._updateFromTableFilter(tableFilterForm);
observer.disconnect();
break;
}
}
});
const debouncedInput = debounce(() => {
const submitLocked = input.getAttribute(ATTR_SUBMIT_LOCKED);
if ((submitLocked === 'false' || submitLocked === null) && (input.value.length === 0 || input.value.length > 2)) {
const submitLocked = input.getAttribute(ATTR_SUBMIT_LOCKED) === 'true';
if (!submitLocked && (input.value.length === 0 || input.value.length > 2)) {
this._updateFromTableFilter(tableFilterForm);
} else if (submitLocked) {
// observe the submit lock of the input element
input.submitLockObserver.observe(input, {
attributes: true,
attributeFilter: [ATTR_SUBMIT_LOCKED],
attributeOldValue: true,
});
}
}, INPUT_DEBOUNCE);
input.addEventListener('input', debouncedInput);

View File

@ -159,11 +159,12 @@ export class Datepicker {
// create a mutation observer that observes the datepicker instance class and sets
// the datepicker-open DOM attribute of the input element if the datepicker has been opened
const datepickerInstanceObserver = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
for (const mutation of mutations) {
if (!mutation.oldValue.includes(DATEPICKER_OPEN_CLASS) && this.datepickerInstance.dt.getAttribute('class').includes(DATEPICKER_OPEN_CLASS)) {
this._element.setAttribute(ATTR_DATEPICKER_OPEN, true);
break;
}
});
}
});
datepickerInstanceObserver.observe(this.datepickerInstance.dt, {
attributes: true,