Skip to content

Commit

Permalink
make component execution preserve immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jun 20, 2019
1 parent a5bcd3b commit fe4bc0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 40 deletions.
25 changes: 8 additions & 17 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1237,19 +1237,17 @@
* Executes a component and modifies it to be the result of the component view.
*
* @param {Object} node
* @returns {Object} component result
*/

function executeComponent(node) {
while (node.type === types.component) {
// Execute the component to get the component view.
// Execute the component to get the component view and update the node.
var nodeName = node.name;
var nodeComponent = components[nodeName](m, node.data, node.children, ms[nodeName]); // Update the node to reflect the component view.

node.type = nodeComponent.type;
node.name = nodeComponent.name;
node.data = nodeComponent.data;
node.children = nodeComponent.children;
node = components[nodeName](m, node.data, node.children, ms[nodeName]);
}

return node;
}
/**
* Creates an old reference node from a view node.
Expand All @@ -1273,9 +1271,7 @@
var nodeChildren = node.children;

for (var i = 0; i < nodeChildren.length; i++) {
var childNew = nodeChildren[i];
executeComponent(childNew);
var childOld = executeCreate(childNew);
var childOld = executeCreate(executeComponent(nodeChildren[i]));
children.push(childOld);
element.appendChild(childOld.element);
} // Set data.
Expand Down Expand Up @@ -1323,9 +1319,7 @@
while (true) {
var nodeOld = nodesOld.pop();
var nodeOldNode = nodeOld.node;
var nodeNew = nodesNew.pop(); // Execute any potential components.

executeComponent(nodeNew);
var nodeNew = executeComponent(nodesNew.pop());

if (nodeOldNode !== nodeNew) {
var nodeOldNodeType = nodeOldNode.type;
Expand Down Expand Up @@ -1507,10 +1501,7 @@
}

for (var _i4 = childrenOldLength; _i4 < childrenNewLength; _i4++) {
var childNew = childrenNew[_i4];
executeComponent(childNew);

var _nodeOldNew = executeCreate(childNew);
var _nodeOldNew = executeCreate(executeComponent(childrenNew[_i4]));

childrenOld.push(_nodeOldNew);
patches.push({
Expand Down
Loading

0 comments on commit fe4bc0a

Please sign in to comment.