Skip to content

Commit

Permalink
Split mount and patch
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 23, 2024
1 parent 14ea8f6 commit 8a81c44
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 31 deletions.
41 changes: 29 additions & 12 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../constants';
import { isArray } from '../util';
import { getDomSibling } from '../component';
import { mount } from './mount';

/**
* Diff the children of a virtual node
Expand Down Expand Up @@ -85,18 +86,34 @@ export function diffChildren(
childVNode._index = i;

// Morph the old element into the new one, but don't append it to the dom yet
let result = diff(
parentDom,
childVNode,
oldVNode,
globalContext,
namespace,
excessDomChildren,
commitQueue,
oldDom,
isHydrating,
refQueue
);
let result;

if (oldVNode !== EMPTY_OBJ) {
result = diff(
parentDom,
childVNode,
oldVNode,
globalContext,
namespace,
excessDomChildren,
commitQueue,
oldDom,
isHydrating,
refQueue
);
} else {
result = mount(
parentDom,
childVNode,
globalContext,
namespace,
excessDomChildren,
commitQueue,
oldDom,
isHydrating,
refQueue
);
}

// Adjust DOM nodes
newDom = childVNode._dom;
Expand Down
2 changes: 1 addition & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function diff(
newVNode._dom = oldDom;
} else {
for (let i = excessDomChildren.length; i--; ) {
removeNode(excessDomChildren[i]);
if (excessDomChildren[i]) excessDomChildren[i].remove();
}
}
} else {
Expand Down
Loading

0 comments on commit 8a81c44

Please sign in to comment.