aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2023-02-13 15:14:26 +0100
committerJoris2023-02-13 21:32:29 +0100
commit4c8aabecf9f9db9f9427ec7bca5cc52c99128c44 (patch)
treeab648c8132f01adbb037041c0b657c242aa89ee8
parent4fb4e101b671056affc6cc67e4670709e36b89c1 (diff)
downloadrx-4c8aabecf9f9db9f9427ec7bca5cc52c99128c44.tar.gz
rx-4c8aabecf9f9db9f9427ec7bca5cc52c99128c44.tar.bz2
rx-4c8aabecf9f9db9f9427ec7bca5cc52c99128c44.zip
Accept attribute undefined
-rw-r--r--src/rx.ts17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/rx.ts b/src/rx.ts
index bf01b6d..2e91e56 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -32,7 +32,8 @@ interface Attributes {
}
type AttributeValue
- = string
+ = undefined
+ | string
| number
| boolean
| ((event: Event) => void)
@@ -386,15 +387,15 @@ function appendNode(base: Element, node: Node, lastAdded?: Node) {
}
function setAttribute(state: State, element: Element, key: string, attribute: AttributeValue) {
- if (typeof attribute == "boolean") {
- if (attribute) {
- // @ts-ignore
- element[key] = "true"
- }
- } else if (typeof attribute == "number") {
+ if (attribute === undefined || attribute === false) {
+ // Do nothing
+ } else if (attribute === true) {
+ // @ts-ignore
+ element[key] = "true"
+ } else if (typeof attribute === "number") {
// @ts-ignore
element[key] = attribute.toString()
- } else if (typeof attribute == "string") {
+ } else if (typeof attribute === "string") {
// @ts-ignore
element[key] = attribute
} else {