UNPKG

cumqueoptio

Version:

The meta-framework suite designed from scratch for frontend-focused modern web development.

48 lines (39 loc) 1.31 kB
import { Model } from '@/types'; export const initializerSymbol = Symbol.for('__reduck_model_initializer__'); export const getModelInitializer = (_model: Model) => _model[initializerSymbol]; export const isModel = (_model: any): _model is Model => _model && Boolean(getModelInitializer(_model)); export const getComputedDepModels = (computed: any) => { const depModels: Model[] = []; const computedArr = Array.isArray(computed) ? computed : [computed]; computedArr.forEach(_computed => { computed && Object.keys(computed).forEach(key => { const selector = computed[key]; if (Array.isArray(selector)) { selector.forEach(s => { if (!depModels.includes(s) && isModel(s)) { depModels.push(s); } }); } }); }); return depModels; }; export enum StateType { Primitive = 'primitive', Array = 'array', Object = 'object', } export const getStateType = (value: any): StateType => { if (Array.isArray(value)) { return StateType.Array; // eslint-disable-next-line eqeqeq } else if (typeof value === 'object' && value != 'undefined') { return StateType.Object; } else { // ignore other types of checking which are not supported by Redux return StateType.Primitive; } };