mirror of
https://github.com/Gongxh0901/kunpolibrary
synced 2025-10-30 02:45:46 +00:00
UI模块添加数据绑定装饰器
1.添加数据基类,子类自动添加代理,数据变化自动通知 2.支持同属性多装饰器
This commit is contained in:
45
src/data/DataBase.ts
Normal file
45
src/data/DataBase.ts
Normal 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__;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user