Skip to content

Commit

Permalink
only update text if changed
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed May 7, 2019
1 parent 7b0542d commit 65eaffe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
21 changes: 12 additions & 9 deletions packages/moon/dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,11 @@
function executeDiff(nodesOld, nodesNew, patches) {
while (true) {
var nodeOld = nodesOld.pop();
var nodeOldNode = nodeOld.node;
var nodeNew = nodesNew.pop(); // If they have the same reference (hoisted) then skip diffing.

if (nodeOld.node !== nodeNew) {
if (nodeOld.node.name !== nodeNew.name) {
if (nodeOldNode !== nodeNew) {
if (nodeOldNode.name !== nodeNew.name) {
// If they have different names, then replace the old node with the
// new one.
patches.push({
Expand All @@ -1084,14 +1085,16 @@
nodeNew: nodeNew,
nodeParent: null
});
} else if (nodeOld.node.type === types.text) {
} else if (nodeOldNode.type === types.text) {
// If they both are text, then update the text content.
patches.push({
type: patchTypes.updateText,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});
if (nodeOldNode.data[""] !== nodeNew.data[""]) {
patches.push({
type: patchTypes.updateText,
nodeOld: nodeOld,
nodeNew: nodeNew,
nodeParent: null
});
}
} else {
// If they both are normal elements, then update attributes, update
// events, and diff the children for appends, deletes, or recursive
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.

21 changes: 12 additions & 9 deletions packages/moon/src/executor/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ function executeView(nodes, parents, indexes) {
function executeDiff(nodesOld, nodesNew, patches) {
while (true) {
const nodeOld = nodesOld.pop();
const nodeOldNode = nodeOld.node;
const nodeNew = nodesNew.pop();

// If they have the same reference (hoisted) then skip diffing.
if (nodeOld.node !== nodeNew) {
if (nodeOld.node.name !== nodeNew.name) {
if (nodeOldNode !== nodeNew) {
if (nodeOldNode.name !== nodeNew.name) {
// If they have different names, then replace the old node with the
// new one.
patches.push({
Expand All @@ -161,14 +162,16 @@ function executeDiff(nodesOld, nodesNew, patches) {
nodeNew,
nodeParent: null
});
} else if (nodeOld.node.type === types.text) {
} else if (nodeOldNode.type === types.text) {
// If they both are text, then update the text content.
patches.push({
type: patchTypes.updateText,
nodeOld,
nodeNew,
nodeParent: null
});
if (nodeOldNode.data[""] !== nodeNew.data[""]) {
patches.push({
type: patchTypes.updateText,
nodeOld,
nodeNew,
nodeParent: null
});
}
} else {
// If they both are normal elements, then update attributes, update
// events, and diff the children for appends, deletes, or recursive
Expand Down

0 comments on commit 65eaffe

Please sign in to comment.