Skip to content

Commit

Permalink
update dynamic expressions and attribute expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed May 13, 2018
1 parent 4b41d73 commit 8118cad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@

var root = {
type: "m-fragment",
attributes: [],
children: [],
dependencies: dependencies
};
Expand Down Expand Up @@ -334,13 +335,14 @@
var generateUpdate = function (element) {
switch (element.type) {
case "m-expression":
return ("m.ut(m[" + (element.index) + "], " + (element.content) + ");");
return element.dynamic ? ("m.ut(m[" + (element.index) + "], " + (element.content) + ");") : "";
break;
case "m-text":
return "";
break;
default:
return mapReduce(element.children, generateUpdate);
var elementPath = "m[" + (element.index) + "]";
return mapReduce(element.attributes, function (attribute) { return attribute.dynamic ? (elementPath + ".setAttribute(\"" + (attribute.key) + "\", " + (attribute.value) + ");") : ""; }) + mapReduce(element.children, generateUpdate);
}
};

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

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

5 changes: 3 additions & 2 deletions src/compiler/generator/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { mapReduce } from "./util";
export const generateUpdate = (element) => {
switch (element.type) {
case "m-expression":
return `m.ut(m[${element.index}], ${element.content});`;
return element.dynamic ? `m.ut(m[${element.index}], ${element.content});` : "";
break;
case "m-text":
return "";
break;
default:
return mapReduce(element.children, generateUpdate);
const elementPath = `m[${element.index}]`;
return mapReduce(element.attributes, (attribute) => attribute.dynamic ? `${elementPath}.setAttribute("${attribute.key}", ${attribute.value});` : "") + mapReduce(element.children, generateUpdate);
}
};
1 change: 1 addition & 0 deletions src/compiler/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const parse = (input) => {

const root = {
type: "m-fragment",
attributes: [],
children: [],
dependencies: dependencies
};
Expand Down

0 comments on commit 8118cad

Please sign in to comment.