!48419 unregister computedid from viewv2

Merge pull request !48419 from LiWenzhen/unregisterComputedId
This commit is contained in:
openharmony_ci 2024-11-20 08:51:42 +00:00 committed by Gitee
commit 85980489a6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 27 additions and 5 deletions

View File

@ -6511,8 +6511,6 @@ class ViewPU extends PUV2ViewBase {
// in case this ViewPU is currently frozen
PUV2ViewBase.inactiveComponents_.delete(`${this.constructor.name}[${this.id__()}]`);
// FIXME needed ?
MonitorV2.clearWatchesFromTarget(this);
this.updateFuncByElmtId.clear();
this.watchedProps.clear();
this.providedVars_.clear();
@ -7452,6 +7450,8 @@ class ObjectProxyHandler {
const conditionalTarget = this.getTarget(target);
// makeObserved logic adds wrapper proxy later
let ret = this.isMakeObserved_ ? target[key] : ObserveV2.autoProxyObject(target, key);
// do not addref for function type, it will make such huge unnecessary dependency collection
// for some common function attributes, e.g. toString etc.
if (typeof (ret) !== 'function') {
ObserveV2.getObserve().addRef(conditionalTarget, key);
return (typeof (ret) === 'object' && this.isMakeObserved_) ? RefInfo.get(ret).proxy : ret;
@ -9102,6 +9102,16 @@ class ComputedV2 {
}
return ret;
}
static clearComputedFromTarget(target) {
var _a;
let meta;
if (!target || typeof target !== 'object' ||
!(meta = target[ObserveV2.COMPUTED_REFS]) || typeof meta !== 'object') {
return;
}
Array.from(Object.values(meta)).forEach((computed) => ObserveV2.getObserve().clearWatch(computed.computedId_));
}
}
// start with high number to avoid same id as elmtId for components.
ComputedV2.MIN_COMPUTED_ID = 0x1000000000;
@ -9274,6 +9284,7 @@ class ViewV2 extends PUV2ViewBase {
PUV2ViewBase.inactiveComponents_.delete(`${this.constructor.name}[${this.id__()}]`);
MonitorV2.clearWatchesFromTarget(this);
ComputedV2.clearComputedFromTarget(this);
this.updateFuncByElmtId.clear();
if (this.parent_) {
this.parent_.removeChild(this);

View File

@ -232,9 +232,6 @@ abstract class ViewPU extends PUV2ViewBase
// in case this ViewPU is currently frozen
PUV2ViewBase.inactiveComponents_.delete(`${this.constructor.name}[${this.id__()}]`);
// FIXME needed ?
MonitorV2.clearWatchesFromTarget(this);
this.updateFuncByElmtId.clear();
this.watchedProps.clear();
this.providedVars_.clear();

View File

@ -108,6 +108,17 @@ class ComputedV2 {
return ret;
}
public static clearComputedFromTarget(target: Object): void {
let meta: Object;
if (!target || typeof target !== 'object' ||
!(meta = target[ObserveV2.COMPUTED_REFS]) || typeof meta !== 'object') {
return;
}
stateMgmtConsole.debug(`ComputedV2: clearComputedFromTarget: from target ${target.constructor?.name} computedIds to clear ${JSON.stringify(Array.from(Object.values(meta)))}`);
Array.from(Object.values(meta)).forEach((computed: ComputedV2) => ObserveV2.getObserve().clearWatch(computed.computedId_));
}
}
interface AsyncAddComputedJobEntryV2 {

View File

@ -61,6 +61,8 @@ class ObjectProxyHandler {
// makeObserved logic adds wrapper proxy later
let ret = this.isMakeObserved_ ? target[key] : ObserveV2.autoProxyObject(target, key);
// do not addref for function type, it will make such huge unnecessary dependency collection
// for some common function attributes, e.g. toString etc.
if (typeof (ret) !== 'function') {
ObserveV2.getObserve().addRef(conditionalTarget, key);
return (typeof (ret) === 'object' && this.isMakeObserved_) ? RefInfo.get(ret).proxy : ret;

View File

@ -152,6 +152,7 @@ abstract class ViewV2 extends PUV2ViewBase implements IView {
PUV2ViewBase.inactiveComponents_.delete(`${this.constructor.name}[${this.id__()}]`);
MonitorV2.clearWatchesFromTarget(this);
ComputedV2.clearComputedFromTarget(this);
this.updateFuncByElmtId.clear();
if (this.parent_) {