UNPKG

nornj

Version:

A powerful template engine that can works with React, JSX enhancement or alternative tools.

56 lines (51 loc) 1.18 kB
import nj from '../core'; import * as tools from '../utils/tools'; export const components = {}; export const componentConfig = new Map(); export function registerComponent(name, component, options) { let params = name, ret; if (!tools.isObject(name)) { params = {}; params[name] = { component, options }; } tools.each(params, (v, k, i) => { let comp; if (v != null) { const { component, options } = v; const name = k.toLowerCase(); comp = component ? component : v; components[name] = comp; componentConfig.set(comp, options); } if (i == 0) { ret = comp; } else { if (i == 1) { ret = [ret]; } ret.push(comp); } }, false); return ret; } export function getComponentConfig(name) { return componentConfig.get(tools.isString(name) ? components[name] || name : name); } export function copyComponentConfig(component, from) { componentConfig.set(component, componentConfig.get(from)); return component; } tools.assign(nj, { components, componentConfig, registerComponent, getComponentConfig, copyComponentConfig });