UNPKG

@vanilla-dom/core

Version:

轻量级 DOM 渲染引擎,VNode 到 DOM 转换

42 lines (41 loc) 1.25 kB
//#region src/pattern-registry.ts const patternRegistry = /* @__PURE__ */ new Map(); /** * 注册组件编码范式 */ function registerComponentPattern(patternName, handler) { patternRegistry.set(patternName, handler); } /** * 获取所有已注册的范式 */ function getAllPatterns() { return Array.from(patternRegistry.entries()).map(([name, handler]) => ({ name, handler })); } /** * 检查组件是否属于已注册的编码范式 */ function isRegisteredComponent(component) { for (const handler of patternRegistry.values()) if (handler.detect(component)) return true; return false; } /** * 获取组件所属的编码范式名称 */ function getComponentPattern(component) { for (const [name, handler] of patternRegistry.entries()) if (handler.detect(component)) return name; return null; } /** * 渲染已注册编码范式的组件 */ function renderRegisteredComponent(component, props, children) { for (const handler of patternRegistry.values()) if (handler.detect(component)) return handler.render(component, props, children); return null; } //#endregion export { getAllPatterns, getComponentPattern, isRegisteredComponent, registerComponentPattern, renderRegisteredComponent }; //# sourceMappingURL=pattern-registry.js.map