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

fix: Replace `sleep` with `requestAnimationFrame` for smoother UI #234

parent 12e08de0
No related branches found
No related tags found
No related merge requests found
......@@ -217,7 +217,6 @@ class TreeMenu extends CustomElement {
* @param value
*/
selectEntry(value) {
this.shadowRoot
.querySelectorAll("[data-monster-role=entry]")
.forEach((entry) => {
......@@ -242,7 +241,7 @@ class TreeMenu extends CustomElement {
let intend = parseInt(currentNode.getAttribute(ATTRIBUTE_INTEND));
if (intend > 0) {
const refSet = new Set()
const refSet = new Set();
let ref = currentNode.previousElementSibling;
while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
......@@ -327,8 +326,7 @@ function initEventHandler() {
this[preventChangeSymbol] = true;
setTimeout(() => {
importEntries.call(this);
},10)
}, 10);
}),
);
});
......@@ -519,7 +517,7 @@ function importEntries() {
setTimeout(() => {
this.setOption("entries", options);
},5)
}, 5);
return this;
}
......
......@@ -180,8 +180,7 @@ class Pathfinder extends Base {
try {
getValueViaPath.call(this, this.object, path, true);
return true;
} catch (e) {
}
} catch (e) {}
return false;
}
......@@ -239,7 +238,9 @@ function getValueViaPath(subject, path, check) {
validateBoolean(check);
if (!(isArray(path) || isString(path))) {
throw new Error("type error: a path must be a string or an array in getValueViaPath");
throw new Error(
"type error: a path must be a string or an array in getValueViaPath",
);
}
let parts;
......@@ -337,8 +338,7 @@ function setValueViaPath(subject, path, value) {
try {
getValueViaPath.call(this, subject, current, true);
break;
} catch (e) {
}
} catch (e) {}
stack.push(current);
parts.pop();
......@@ -416,7 +416,9 @@ function assignProperty(object, key, value) {
*/
function deleteValueViaPath(subject, path) {
if (!(isArray(path) || isString(path))) {
throw new Error("type error: a path must be a string or an array in deleteValueViaPath");
throw new Error(
"type error: a path must be a string or an array in deleteValueViaPath",
);
}
let parts;
......
......@@ -40,6 +40,7 @@ import { addAttributeToken, addToObjectLink } from "./attributes.mjs";
import { updaterTransformerMethodsSymbol } from "./customelement.mjs";
import { findTargetElementFromEvent } from "./events.mjs";
import { findDocumentTemplate } from "./template.mjs";
import { getWindow } from "./util.mjs";
export { Updater, addObjectWithUpdaterToElement };
......@@ -111,11 +112,15 @@ class Updater extends Base {
for (const [, change] of Object.entries(diffResult)) {
promises.push(
Sleep(1).then(() => {
new Promise((resolve) => {
getWindow().requestAnimationFrame(() => {
removeElement.call(this, change);
insertElement.call(this, change);
updateContent.call(this, change);
updateAttributes.call(this, change);
resolve();
});
}),
);
}
......@@ -534,7 +539,7 @@ function insertElement(change) {
const available = new Set();
for (const [i, ] of Object.entries(value)) {
for (const [i] of Object.entries(value)) {
const ref = refPrefix + i;
const currentPath = `${dataPath}.${i}`;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment