Skip to content

Commit

Permalink
remove fragments because they have no parent node
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 28, 2019
1 parent 61da3cf commit f071af6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 64 deletions.
49 changes: 18 additions & 31 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
var types = {
element: 0,
text: 1,
component: 2,
fragment: 3
component: 2
};
/**
* Logs an error message to the console.
Expand Down Expand Up @@ -626,8 +625,6 @@
return generateNodeIf(element, parent, index);
} else if (name === "text") {
type = types.text;
} else if (name === "fragment") {
type = types.fragment;
} else if (name[0] === name[0].toLowerCase()) {
type = types.element;
} else {
Expand Down Expand Up @@ -779,26 +776,20 @@

nodeData[""] = textContent;
} else {
var _data = node.data;
var _data = node.data; // Create a DOM element.

if (nodeType === types.element) {
// Create a DOM element.
nodeNode = document.createElement(node.name); // Set data, events, and attributes.
nodeNode = document.createElement(node.name); // Set data, events, and attributes.

for (var key in _data) {
var value = _data[key];
for (var key in _data) {
var value = _data[key];

if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
} else {
// Create a DOM fragment.
nodeNode = document.createDocumentFragment();
} // Recursively append children.


Expand Down Expand Up @@ -913,17 +904,13 @@
});
} else {
// If they both are normal elements, then set attributes and diff the
// children for appends, deletes, or recursive updates. This skips
// updating attributes for fragments.
if (nodeOld.type === types.element) {
patches.push({
type: patchTypes.setAttributes,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});
}

// children for appends, deletes, or recursive updates.
patches.push({
type: patchTypes.setAttributes,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});
var childrenOld = nodeOld.data.children;
var childrenNew = nodeNew.data.children;
var childrenOldLength = childrenOld.length;
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.

2 changes: 0 additions & 2 deletions packages/moon/src/compiler/generator/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export function generateNode(element, parent, index) {
return generateNodeIf(element, parent, index);
} else if (name === "text") {
type = types.text;
} else if (name === "fragment") {
type = types.fragment;
} else if (name[0] === name[0].toLowerCase()) {
type = types.element;
} else {
Expand Down
48 changes: 20 additions & 28 deletions packages/moon/src/executor/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,20 @@ function executeCreate(node) {
} else {
const data = node.data;

if (nodeType === types.element) {
// Create a DOM element.
nodeNode = document.createElement(node.name);

// Set data, events, and attributes.
for (let key in data) {
const value = data[key];

if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
// Create a DOM element.
nodeNode = document.createElement(node.name);

// Set data, events, and attributes.
for (let key in data) {
const value = data[key];

if (key[0] === "@") {
nodeData[key] = value;
nodeNode.addEventListener(key.slice(1), value);
} else if (key !== "children") {
nodeData[key] = value;
nodeNode.setAttribute(key, value);
}
} else {
// Create a DOM fragment.
nodeNode = document.createDocumentFragment();
}

// Recursively append children.
Expand Down Expand Up @@ -185,16 +180,13 @@ function executeDiff(nodesOld, nodesNew, patches) {
});
} else {
// If they both are normal elements, then set attributes and diff the
// children for appends, deletes, or recursive updates. This skips
// updating attributes for fragments.
if (nodeOld.type === types.element) {
patches.push({
type: patchTypes.setAttributes,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});
}
// children for appends, deletes, or recursive updates.
patches.push({
type: patchTypes.setAttributes,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});

const childrenOld = nodeOld.data.children;
const childrenNew = nodeNew.data.children;
Expand Down
3 changes: 1 addition & 2 deletions packages/moon/src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
export const types = {
element: 0,
text: 1,
component: 2,
fragment: 3
component: 2
};

/**
Expand Down

0 comments on commit f071af6

Please sign in to comment.