Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf #3956

Merged
merged 2 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { diff, unmount, applyRef } from './index';
import { createVNode, Fragment } from '../create-element';
import { EMPTY_OBJ, EMPTY_ARR } from '../constants';
import { getDomSibling } from '../component';
import { isArray } from '../util';

/**
* Diff the children of a virtual node
Expand Down Expand Up @@ -70,7 +71,7 @@ export function diffChildren(
null,
childVNode
);
} else if (Array.isArray(childVNode)) {
} else if (isArray(childVNode)) {
childVNode = newParentVNode._children[i] = createVNode(
Fragment,
{ children: childVNode },
Expand Down Expand Up @@ -265,7 +266,7 @@ function reorderChildren(childVNode, oldDom, parentDom) {
export function toChildArray(children, out) {
out = out || [];
if (children == null || typeof children == 'boolean') {
} else if (Array.isArray(children)) {
} else if (isArray(children)) {
children.some(child => {
toChildArray(child, out);
});
Expand Down
6 changes: 3 additions & 3 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, getDomSibling } from '../component';
import { Fragment } from '../create-element';
import { diffChildren } from './children';
import { diffProps, setProperty } from './props';
import { assign, removeNode, slice } from '../util';
import { assign, isArray, removeNode, slice } from '../util';
import options from '../options';

/**
Expand Down Expand Up @@ -232,7 +232,7 @@ export function diff(

diffChildren(
parentDom,
Array.isArray(renderResult) ? renderResult : [renderResult],
isArray(renderResult) ? renderResult : [renderResult],
newVNode,
oldVNode,
globalContext,
Expand Down Expand Up @@ -438,7 +438,7 @@ function diffElementNodes(
i = newVNode.props.children;
diffChildren(
dom,
Array.isArray(i) ? i : [i],
isArray(i) ? i : [i],
newVNode,
oldVNode,
globalContext,
Expand Down
2 changes: 2 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { EMPTY_ARR } from './constants';

export const isArray = Array.isArray;

/**
* Assign properties from `props` to `obj`
* @template O, P The obj and props types
Expand Down