Skip to content

Commit

Permalink
test perf of less arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Apr 30, 2024
1 parent a832512 commit f46840e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { getDomSibling } from '../component';
*/
export function diffChildren(
parentDom,
renderResult,
newParentVNode,
oldParentVNode,
globalContext,
Expand All @@ -54,10 +53,14 @@ export function diffChildren(
/** @type {VNode[]} */
let oldChildren = (oldParentVNode && oldParentVNode._children) || EMPTY_ARR;

let newChildrenLength = renderResult.length;
let newChildrenLength = newParentVNode._children.length;

newParentVNode._nextDom = oldDom;
constructNewChildrenArray(newParentVNode, renderResult, oldChildren);
constructNewChildrenArray(
newParentVNode,
newParentVNode._children,
oldChildren
);
oldDom = newParentVNode._nextDom;

for (i = 0; i < newChildrenLength; i++) {
Expand Down
6 changes: 4 additions & 2 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ export function diff(
tmp != null && tmp.type === Fragment && tmp.key == null;
let renderResult = isTopLevelFragment ? tmp.props.children : tmp;

newVNode._children = isArray(renderResult)
? renderResult
: [renderResult];
diffChildren(
parentDom,
isArray(renderResult) ? renderResult : [renderResult],
newVNode,
oldVNode,
globalContext,
Expand Down Expand Up @@ -490,9 +492,9 @@ function diffElementNodes(
} else {
if (oldHtml) dom.innerHTML = '';

newVNode._children = isArray(newChildren) ? newChildren : [newChildren];

Check failure on line 495 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test

Type 'ComponentChild[]' is not assignable to type 'VNode<any>[]'.

Check failure on line 495 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Type 'ComponentChild[]' is not assignable to type 'VNode<any>[]'.
diffChildren(
dom,
isArray(newChildren) ? newChildren : [newChildren],
newVNode,
oldVNode,
globalContext,
Expand Down

0 comments on commit f46840e

Please sign in to comment.