From 5ab32e9cf85cebb503f788d779ea883b1149cb76 Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Sat, 14 Oct 2017 10:21:42 +0200 Subject: [PATCH] remove unused code, small refactor --- src/utils/assist.js | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/utils/assist.js b/src/utils/assist.js index a2d4c922..227a3c56 100644 --- a/src/utils/assist.js +++ b/src/utils/assist.js @@ -189,20 +189,12 @@ function findComponentUpward (context, componentName, componentNames) { export {findComponentUpward}; // Find component downward -function findComponentDownward (context, componentName) { +export function findComponentDownward (context, componentName) { const childrens = context.$children; let children = null; if (childrens.length) { - childrens.forEach(child => { - const name = child.$options.name; - if (name === componentName) { - children = child; - } - }); - - for (let i = 0; i < childrens.length; i++) { - const child = childrens[i]; + for (const child of childrens) { const name = child.$options.name; if (name === componentName) { children = child; @@ -215,27 +207,15 @@ function findComponentDownward (context, componentName) { } return children; } -export {findComponentDownward}; // Find components downward -function findComponentsDownward (context, componentName, components = []) { - const childrens = context.$children; - - if (childrens.length) { - childrens.forEach(child => { - const name = child.$options.name; - const childs = child.$children; - - if (name === componentName) components.push(child); - if (childs.length) { - const findChilds = findComponentsDownward(child, componentName, components); - if (findChilds) components.concat(findChilds); - } - }); - } - return components; +export function findComponentsDownward (context, componentName) { + return context.$children.reduce((components, child) => { + if (child.$options.name === componentName) components.push(child); + const foundChilds = findComponentsDownward(child, componentName); + return components.concat(foundChilds); + }, []); } -export {findComponentsDownward}; /* istanbul ignore next */ const trim = function(string) { @@ -297,4 +277,4 @@ export function removeClass(el, cls) { if (!el.classList) { el.className = trim(curClass); } -} \ No newline at end of file +}