debounce .draw()

This commit is contained in:
sparks-alec
2024-11-02 22:15:59 -04:00
parent a6bcac5adf
commit 97c118bf99
+14 -6
View File
@@ -100,13 +100,21 @@ module.exports.draw = function draw(device) {
const d = device;
const $deviceDrawArea = document.getElementById(`device-${d.id}-draw-area`);
if ($deviceDrawArea) {
const scriptEl = $deviceDrawArea.contentWindow.document.createRange().createContextualFragment(generateBodyHTML(d));
$deviceDrawArea.contentWindow.document.body.replaceChildren(scriptEl);
} else {
drawDeviceFrame(d.id);
if (device.drawTimeout !== undefined) {
clearTimeout(device.drawTimeout);
}
d.drawn = true;
d.drawTimeout = setTimeout(() => {
if ($deviceDrawArea) {
const scriptEl = $deviceDrawArea.contentWindow.document
.createRange()
.createContextualFragment(generateBodyHTML(d));
$deviceDrawArea.contentWindow.document.body.replaceChildren(scriptEl);
} else {
drawDeviceFrame(d.id);
}
d.drawn = true;
}, 200);
};
module.exports.update = function update(device, type, data) {