/**
 *@author       谢辉
 *@date         2018/12/6 13:03
 *@Copyright    天源迪科信息技术股份有限公司
 *@Description
 */
import Vue from 'vue';
const isServer = Vue.prototype.$isServer;
// 判断参数是否是其中之一
export function oneOf (value, validList) {
    for (let i = 0; i < validList.length; i++) {
        if (value === validList[i]) {
            return true;
        }
    }
    return false;
}
// watch DOM change
export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
// Find components downward
export function findComponentsDownward (context, componentName, ignoreComponentNames = []) {
    if (!Array.isArray(ignoreComponentNames)) {
        ignoreComponentNames = [ignoreComponentNames]
    }
    return context.$children.reduce((components, child) => {
        if (child.$options.name === componentName) components.push(child);
        if (ignoreComponentNames.indexOf(child.$options.name) < 0) {
            const foundChilds = findComponentsDownward(child, componentName);
            return components.concat(foundChilds);
        } else {
            return components
        }
    }, []);
}
