From 957f74d2a0e5734ebf1d46b89488c86ddf465650 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Fri, 6 Nov 2020 14:34:58 -0500 Subject: [PATCH] Don't use foreach in observers and return when done --- kiosk-mode.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/kiosk-mode.js b/kiosk-mode.js index 8ba055f..107a81c 100644 --- a/kiosk-mode.js +++ b/kiosk-mode.js @@ -92,37 +92,42 @@ new MutationObserver(lovelaceWatch).observe(panel, { childList: true }); // If new lovelace panel was added watch for hui-root to appear. function lovelaceWatch(mutations) { - mutations.forEach(({ addedNodes }) => { - addedNodes.forEach((e) => { - if (e.localName == "ha-panel-lovelace") { - new MutationObserver(rootWatch).observe(e.shadowRoot, { + for (let mutation of mutations) { + for (let node of mutation.addedNodes) { + if (node.localName == "ha-panel-lovelace") { + new MutationObserver(rootWatch).observe(node.shadowRoot, { childList: true, }); + return; } - }); - }); + } + } } // When hui-root appears watch it's children. function rootWatch(mutations) { - mutations.forEach(({ addedNodes }) => { - addedNodes.forEach((e) => { - if (e.localName == "hui-root") { - new MutationObserver(appLayoutWatch).observe(e.shadowRoot, { + for (let mutation of mutations) { + for (let node of mutation.addedNodes) { + if (node.localName == "hui-root") { + new MutationObserver(appLayoutWatch).observe(node.shadowRoot, { childList: true, }); + return; } - }); - }); + } + } } // When ha-app-layout appears we can run. function appLayoutWatch(mutations) { - mutations.forEach(({ addedNodes }) => { - addedNodes.forEach((e) => { - if (e.localName == "ha-app-layout") kiosk_mode(); - }); - }); + for (let mutation of mutations) { + for (let node of mutation.addedNodes) { + if (node.localName == "ha-app-layout") { + kiosk_mode(); + return; + } + } + } } // Overly complicated console tag.