|
|
@ -7,6 +7,8 @@ export const ISPROXYKEY = "_isProxy";
|
|
|
|
* 如果属性是数组,那么自动添加`Proxy`.
|
|
|
|
* 如果属性是数组,那么自动添加`Proxy`.
|
|
|
|
* 可以使用`ISPROXYKEY`覆盖这个函数的代理行为(使用CADObject.CreateProxyArray快速覆盖)
|
|
|
|
* 可以使用`ISPROXYKEY`覆盖这个函数的代理行为(使用CADObject.CreateProxyArray快速覆盖)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* ! 仅在{数组}或者{值}类型上使用,如果是Object,请使用AutoRecordObject
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param target
|
|
|
|
* @param target
|
|
|
|
* @param property
|
|
|
|
* @param property
|
|
|
|
* @param [descriptor]
|
|
|
|
* @param [descriptor]
|
|
|
@ -72,3 +74,69 @@ export function AutoRecord(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function AutoRecordObject(
|
|
|
|
|
|
|
|
target: { WriteAllObjectRecord: () => void; },
|
|
|
|
|
|
|
|
property: string,
|
|
|
|
|
|
|
|
descriptor?: PropertyDecorator)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let privateKey = '__' + property;
|
|
|
|
|
|
|
|
Object.defineProperty(target, property,
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (value instanceof Object)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!this[privateKey])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (value[ISPROXYKEY])
|
|
|
|
|
|
|
|
this[privateKey] = value;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
this[privateKey] = new Proxy(value, {
|
|
|
|
|
|
|
|
set: (target, key, value, receiver) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Reflect.get(target, key, receiver) !== value)
|
|
|
|
|
|
|
|
this.WriteAllObjectRecord();
|
|
|
|
|
|
|
|
return Reflect.set(target, key, value, receiver);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
get: (target, key, receiver) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (key === ISPROXYKEY)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return Reflect.get(target, key, receiver);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let obj = this[privateKey] as any;
|
|
|
|
|
|
|
|
for (let key in value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (obj[key] !== value[key])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.WriteAllObjectRecord();
|
|
|
|
|
|
|
|
obj[key] = value[key];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let oldv = this[privateKey];
|
|
|
|
|
|
|
|
if (oldv !== value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.WriteAllObjectRecord();
|
|
|
|
|
|
|
|
this[privateKey] = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return this[privateKey];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
enumerable: true,
|
|
|
|
|
|
|
|
configurable: true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|