Skip to content

Commit

Permalink
add support for boolean attributes (fixes #238)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 28, 2019
1 parent a51aced commit acd98dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@
if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
} else if (key !== "children" && value !== false) {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
Expand Down Expand Up @@ -1057,7 +1057,12 @@

if (key[0] !== "@" && key !== "children") {
nodeOldData[key] = value;
nodeOldNode.setAttribute(key, value);

if (value === false) {
nodeOldNode.removeAttribute(key);
} else {
nodeOldNode.setAttribute(key, value);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/moon/dist/moon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions packages/moon/src/executor/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function executeCreate(node) {
if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
} else if (key !== "children" && value !== false) {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
Expand Down Expand Up @@ -289,7 +289,12 @@ function executePatch(patches) {

if (key[0] !== "@" && key !== "children") {
nodeOldData[key] = value;
nodeOldNode.setAttribute(key, value);

if (value === false) {
nodeOldNode.removeAttribute(key);
} else {
nodeOldNode.setAttribute(key, value);
}
}
}

Expand Down

0 comments on commit acd98dc

Please sign in to comment.