From 2b509c06b79bd5f61d07c7ed00f67553ba58a6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Gunnar=20Staal?= Date: Thu, 23 Nov 2023 13:07:08 +0100 Subject: [PATCH] cleanup + comments --- WindowManager.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/WindowManager.js b/WindowManager.js index 19b8759..7253db6 100644 --- a/WindowManager.js +++ b/WindowManager.js @@ -11,9 +11,9 @@ class WindowManager { let that = this; + // event listener for when localStorage is changed from another window addEventListener("storage", (event) => { - //console.log(event) if (event.key == "windows") { let newWindows = JSON.parse(event.newValue); @@ -23,25 +23,23 @@ class WindowManager if (winChange) { - //console.log("change"); - //console.log("windows", that.#windows); - //console.log("newWindows", newWindows); if (that.#winChangeCallback) that.#winChangeCallback(); } } - - //console.log(that.#windows); }); + // event listener for when current window is about to ble closed window.addEventListener('beforeunload', function (e) { let index = that.getWindowIndexFromId(that.#id); + //remove this window from the list and update local storage that.#windows.splice(index, 1); that.updateWindowsLocalStorage(); }); } + // check if theres any changes to the window list #didWindowsChange (pWins, nWins) { if (pWins.length != nWins.length) @@ -61,7 +59,7 @@ class WindowManager } } - + // initiate current window (add metadata for custom data to store with each window instance) init (metaData) { this.#windows = JSON.parse(localStorage.getItem("windows")) || [];