diff --git a/src/create-element.js b/src/create-element.js index ce1f9a3171..b6be79c424 100644 --- a/src/create-element.js +++ b/src/create-element.js @@ -1,5 +1,6 @@ import { UNDEFINED } from './constants'; import options from './options'; +import { isArray } from './util'; let vnodeId = 0; @@ -65,7 +66,7 @@ export function normalizeToVNode(childVNode) { } if (type == 'object' || type == 'function') { - if (Array.isArray(childVNode)) { + if (isArray(childVNode)) { return createElement(Fragment, null, childVNode); } diff --git a/src/diff/children.js b/src/diff/children.js index 4eabaf8b7e..fb402cdca2 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -12,6 +12,7 @@ import { mount } from './mount'; import { patch } from './patch'; import { unmount } from './unmount'; import { createInternal, getDomSibling } from '../tree'; +import { isArray } from '../util'; /** * Update an internal with new children. @@ -274,7 +275,7 @@ export function insertComponentDom(internal, nextSibling, parentDom) { export function toChildArray(children, out) { out = out || []; if (children == null || typeof children == 'boolean') { - } else if (Array.isArray(children)) { + } else if (isArray(children)) { for (children of children) { toChildArray(children, out); } diff --git a/src/diff/mount.js b/src/diff/mount.js index 81162f518b..632cb5b7bb 100644 --- a/src/diff/mount.js +++ b/src/diff/mount.js @@ -19,6 +19,7 @@ import { createInternal, getParentContext } from '../tree'; import options from '../options'; import { ENABLE_CLASSES } from '../component'; import { commitQueue } from './commit'; +import { isArray } from '../util'; /** * Diff two virtual nodes and apply proper changes to the DOM * @param {import('../internal').Internal} internal The Internal node to mount @@ -201,7 +202,7 @@ function mountElement(internal, dom, refs) { } else if (newChildren != null) { mountChildren( internal, - Array.isArray(newChildren) ? newChildren : [newChildren], + isArray(newChildren) ? newChildren : [newChildren], dom, isNew ? null : dom.firstChild, refs @@ -409,7 +410,7 @@ function mountComponent(internal, startDom) { if (renderResult.type === Fragment && renderResult.key == null) { renderResult = renderResult.props.children; } - if (!Array.isArray(renderResult)) { + if (!isArray(renderResult)) { renderResult = [renderResult]; } } else { diff --git a/src/diff/patch.js b/src/diff/patch.js index aa1c9cbc4d..e6c4101aee 100644 --- a/src/diff/patch.js +++ b/src/diff/patch.js @@ -23,6 +23,7 @@ import { mountChildren } from './mount'; import { Fragment } from '../create-element'; import { ENABLE_CLASSES } from '../component'; import { commitQueue } from './commit'; +import { isArray } from '../util'; /** * Diff two virtual nodes and apply proper changes to the DOM @@ -182,7 +183,7 @@ function patchElement(internal, vnode) { if (oldHtml) dom.innerHTML = ''; patchChildren( internal, - newChildren && Array.isArray(newChildren) ? newChildren : [newChildren], + newChildren && isArray(newChildren) ? newChildren : [newChildren], dom ); } @@ -311,7 +312,7 @@ function patchComponent(internal, newVNode) { if (renderResult.type === Fragment && renderResult.key == null) { renderResult = renderResult.props.children; } - if (!Array.isArray(renderResult)) { + if (!isArray(renderResult)) { renderResult = [renderResult]; } } else { diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000000..3d67de5c37 --- /dev/null +++ b/src/util.js @@ -0,0 +1 @@ +export const isArray = Array.isArray;