Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Don't use foreach in observers and return when done
Browse files Browse the repository at this point in the history
  • Loading branch information
maykar authored Nov 6, 2020
1 parent bbdd71a commit 957f74d
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions kiosk-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 957f74d

Please sign in to comment.