From 4e5391333199a6c3fae31f57d83bc4a3873f9a0d Mon Sep 17 00:00:00 2001 From: Matt Mo Date: Thu, 30 Jul 2020 10:11:09 -0700 Subject: [PATCH] Dont store empty classes or events if they are null upon change. --- src/ignite-template.js | 13 +++++++++++-- src/sheet.js | 15 +++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ignite-template.js b/src/ignite-template.js index 17fc0af..aedab04 100644 --- a/src/ignite-template.js +++ b/src/ignite-template.js @@ -276,8 +276,13 @@ class IgniteTemplate { } } + //Remove the old value this.classes = this.classes.filter(cl => cl != oldValue && cl != newValue); - this.classes.push(newValue); + + //Add the new value if its valid. + if (newValue !== null && newValue !== undefined) { + this.classes.push(newValue); + } } /** @@ -353,7 +358,11 @@ class IgniteTemplate { //Remove the old value from the events this.events[eventName] = this.events[eventName].filter(ev => ev != oldValue); - this.events[eventName].push(newValue); + + //Add the new value if it's needed + if (newValue !== null && newValue !== undefined) { + this.events[eventName].push(newValue); + } } } } diff --git a/src/sheet.js b/src/sheet.js index 6c3f914..8299520 100644 --- a/src/sheet.js +++ b/src/sheet.js @@ -12,7 +12,8 @@ class Sheet extends IgniteElement { items: ["1", "2"], href: "www.google.com", name: "default content", - linkClick: this.onClick + linkClick: this.onClick1, + linkClick2: this.onClick2 }; } @@ -29,15 +30,17 @@ class Sheet extends IgniteElement { new html("

---- begin sheet's slot ----

"), new slot(this), new html("

---- end of slot ----

"), - new a("I go nowhere, but you can click me ;)").on("click", this.linkClick) + new a("I go nowhere, but you can click me ;)").on("click", this.linkClick).on("click", this.linkClick2) ) ); } - onClick(event) { - console.log("Element was clicked!"); - console.log("Event:"); - console.log(event); + onClick1(event) { + console.log("Element was clicked 1!"); + } + + onClick2(event) { + console.log("Element was clicked 2!"); } }