UI模块添加数据绑定装饰器

1.添加数据基类,子类自动添加代理,数据变化自动通知
 2.支持同属性多装饰器
This commit is contained in:
gongxh
2025-08-29 15:25:10 +08:00
parent b62a4af8db
commit e48011d941
45 changed files with 1354 additions and 21 deletions

45
src/data/DataBase.ts Normal file
View File

@@ -0,0 +1,45 @@
import { BindManager } from './BindManager';
import { ProxyObject } from './ProxyHandler';
import { BindInfo } from './types';
/**
* 响应式数据基类
* 通过 Proxy 拦截属性访问,实现零侵入式响应式数据绑定
*/
export class DataBase {
/** 响应式对象唯一标识 */
private __data_id__: string;
/** 绑定器集合 */
private __watchers__: Set<BindInfo>;
/** 是否已销毁 */
private __destroyed__: boolean = false;
constructor() {
// 返回包装后的对象,自动使用 constructor.name
return ProxyObject(this);
}
/**
* 销毁响应式对象,清理所有绑定器
*/
public destroy(): void {
this.__destroyed__ = true;
this.__watchers__.clear();
BindManager.cleanup(this);
}
/**
* 获取响应式对象ID
*/
public getDataId(): string {
return this.__data_id__;
}
/**
* 检查是否已销毁
*/
public isDestroyed(): boolean {
return this.__destroyed__;
}
}