From 63f24aaeddfbe7955c047f8878c33b0484611c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Sat, 13 Aug 2022 20:58:33 +0100 Subject: [PATCH] Clean up flash button logic a bit --- src/lib/js/index.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/lib/js/index.ts b/src/lib/js/index.ts index 52b7ce1..5612a53 100644 --- a/src/lib/js/index.ts +++ b/src/lib/js/index.ts @@ -1,22 +1,16 @@ function registerFlashCloseButtons() { const flashButtons = document.querySelectorAll(".notification .delete"); - flashButtons.forEach((button) => { - const flash = button.parentNode; - - if (flash === null) { - console.error( - "Unreachable because our `querySelector` includes a parent; something went very wrong" - ); - return; + for (const flashButton of flashButtons) { + if (flashButton.parentNode === null) { + throw new Error("invalid flash button"); } + const flash = flashButton.parentNode; + flash.addEventListener("click", () => { if (flash.parentNode === null) { - console.error( - "Notification not placed in DOM; something went very wrong" - ); - return; + throw new Error("invalid flash message"); } flash.parentNode.removeChild(flash); @@ -38,7 +32,7 @@ function registerFlashCloseButtons() { const block = flash.parentNode; flash.parentNode.parentNode.removeChild(block); } - }); + } } function registerNavCollapseButtons() {