You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

/**
* 组件系统模块
* 提供组件的注册和创建功能
*/
const component = {
/**
* 组件存储
*/
components: {},
/**
* 注册组件
* @param {string} name - 组件名称
* @param {Function} constructor - 组件构造函数
*/
register: function(name, constructor) {
this.components[name] = constructor;
},
/**
* 创建组件实例
* @param {string} name - 组件名称
* @param {Object} props - 组件属性
* @param {Element} container - 容器元素
* @returns {Object} - 组件实例
*/
create: function(name, props = {}, container = null) {
if (!this.components || !this.components[name]) {
throw new Error(`Component ${name} not registered`);
}
const Component = this.components[name];
const instance = new Component(props);
if (container) {
instance.mount(container);
}
return instance;
}
};
// 导出组件模块
module.exports = component;