Skip to content
Snippets Groups Projects
Verified Commit 8d18bcc4 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: Refactor Select and Updater for improved readability and functionality

Summary of changes
- Updated `select.mjs` to clarify observer context
- Refactored `updater.mjs` for cleaner change application

In `select.mjs`:
- Added a comment to indicate the observer context is a `ProxyObserver`, improving code readability and making intentions clear.
- This change helps future developers quickly understand the purpose of the code, reducing potential confusion.

In `updater.mjs`:
- Simplified the while loop condition to check `this[pendingDiffsSymbol].length` directly.
- Refactored the change application logic into a private method `#applyChange`, consolidating the steps of removing, inserting, updating content, and attributes into a single place.
- This makes the code cleaner and more maintainable, reducing duplication and enhancing readability.
parent 2e0135fe
No related branches found
No related tags found
No related merge requests found
......@@ -608,9 +608,9 @@ class Select extends CustomControl {
let lastValue = self.value;
self[internalSymbol].attachObserver(
new Observer(function () {
// this is here not the Control, but the ProxyObserver
if (isObject(this) && this instanceof ProxyObserver) {
const n = this.getSubject()?.options?.value;
if (lastValue !== n && n !== undefined) {
lastValue = n;
setSelection
......@@ -806,6 +806,7 @@ class Select extends CustomControl {
* @returns {any}
*/
function importOptionsIntern(data) {
const self = this;
const mappingOptions = this.getOption("mapping", {});
const selector = mappingOptions?.["selector"];
......
......@@ -154,26 +154,25 @@ class Updater extends Base {
}
this[processingSymbol] = true;
while (this[pendingDiffsSymbol].length > 0) {
while (this[pendingDiffsSymbol].length) {
const diffResult = this[pendingDiffsSymbol].shift();
for (const [, change] of Object.entries(diffResult)) {
await new Promise((resolve, reject) => {
try {
removeElement.call(this, change);
insertElement.call(this, change);
updateContent.call(this, change);
updateAttributes.call(this, change);
resolve();
} catch (err) {
reject(err);
}
});
for (const change of Object.values(diffResult)) {
await this.#applyChange(change);
}
}
this[processingSymbol] = false;
}
/** @private **/
async #applyChange(change) {
removeElement.call(this, change);
insertElement.call(this, change);
updateContent.call(this, change);
await Promise.resolve();
updateAttributes.call(this, change);
}
/**
* Defaults: 'keyup', 'click', 'change', 'drop', 'touchend'
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment