From cc64678ff1cee9129976c153da9d237b858f6d86 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 21 Mar 2023 18:03:31 -0300 Subject: data steps: fix property-from-attribute setter/getters --- src/util/html.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/util/html.js') diff --git a/src/util/html.js b/src/util/html.js index c5aa0569..cb4a84e8 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -150,15 +150,14 @@ export class Tag { #setAttributeFlag(attribute, value) { if (value) { - return this.attributes[attribute] = true; + this.attributes.set(attribute, true); } else { - delete this.attributes[attribute]; - return false; + this.attributes.remove(attribute); } } #getAttributeFlag(attribute) { - return !!this.attributes[attribute]; + return !!this.attributes.get(attribute); } #setAttributeString(attribute, value) { @@ -166,15 +165,15 @@ export class Tag { // distinctly from null/undefined. if (value === undefined || value === null) { - delete this.attributes[value]; + this.attributes.remove(attribute); return undefined; } else { - this.attributes[value] = String(value); + this.attributes.set(attribute, String(value)); } } #getAttributeString(attribute) { - const value = this.attributes[attribute]; + const value = this.attributes.get(attribute); if (value === undefined || value === null) { return undefined; @@ -295,6 +294,23 @@ export class Attributes { return this.#attributes; } + set(attribute, value) { + if (value === null || value === undefined) { + this.remove(attribute); + } else { + this.#attributes[attribute] = value; + } + return value; + } + + get(attribute) { + return this.#attributes[attribute]; + } + + remove(attribute) { + return delete this.#attributes[attribute]; + } + toString() { return Object.entries(this.attributes) .map(([key, val]) => { -- cgit 1.3.0-6-gf8a5