diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-21 18:03:31 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-21 18:03:31 -0300 |
commit | cc64678ff1cee9129976c153da9d237b858f6d86 (patch) | |
tree | 106e863ca425219ee8058b41fa647b2e225d4175 /src/util | |
parent | b5e4efc554af05e57770a84eb4991aea43697150 (diff) |
data steps: fix property-from-attribute setter/getters
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/html.js | 30 |
1 files changed, 23 insertions, 7 deletions
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]) => { |