From 9467942b7a8ae31a3a55f104a835c74a46f47974 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 5 Apr 2017 13:04:07 +0800 Subject: [PATCH] split get-first-component-child --- src/core/vdom/helpers/get-first-component-child.js | 14 ++++++++++++++ src/core/vdom/helpers/index.js | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/core/vdom/helpers/get-first-component-child.js diff --git a/src/core/vdom/helpers/get-first-component-child.js b/src/core/vdom/helpers/get-first-component-child.js new file mode 100644 index 00000000..70b2f199 --- /dev/null +++ b/src/core/vdom/helpers/get-first-component-child.js @@ -0,0 +1,14 @@ +/* @flow */ + +import { isDef } from 'shared/util' + +export function getFirstComponentChild (children: ?Array): ?VNode { + if (Array.isArray(children)) { + for (let i = 0; i < children.length; i++) { + const c = children[i] + if (isDef(c) && isDef(c.componentOptions)) { + return c + } + } + } +} diff --git a/src/core/vdom/helpers/index.js b/src/core/vdom/helpers/index.js index 3994d098..a1541e10 100644 --- a/src/core/vdom/helpers/index.js +++ b/src/core/vdom/helpers/index.js @@ -5,7 +5,4 @@ export * from './extract-props' export * from './update-listeners' export * from './normalize-children' export * from './resolve-async-component' - -export function getFirstComponentChild (children: ?Array): ?VNode { - return children && children.filter((c: VNode) => c && c.componentOptions)[0] -} +export * from './get-first-component-child'