123456789101112131415161718192021222324252627282930313233343536 |
- /**网络变量基类*/
- export class NetBase {
- private _id: string;
- public get Id(): string { return this._id };
- private dataMap: { [key: string]: any } = {};
- private dirtyMap: { [key: string]: any } = {};
- constructor(id: string) {
- this._id = id;
- this.dataMap = {};
- }
- /**初始变量值*/
- public initValue(data: { [key: string]: any }): void {
- this.dataMap = data ?? {};
- }
- /**修改某个键的值*/
- protected setValue(key: string, value: any): void {
- this.dataMap[key] = value;
- }
- protected setValueDirty(key: string, value: any): void {
- this.dirtyMap[key] = value;
- }
- /**获取数据的值*/
- protected getValue(key: string): any {
- return this.dataMap[key];
- }
- /**处理脏数据*/
- private doDirtyData(f: (data: { [key: string]: any }) => void): void {
- if (Object.keys(this.dirtyMap).length === 0) return null;
- f(this.dirtyMap);
- this.dirtyMap = {};
- }
- protected dispose(): void {
- this.dataMap = {};
- this.dirtyMap = {};
- }
- }
|