From ecc1c6c0d10b9c3e334537ef264b0d6ab55c0f43 Mon Sep 17 00:00:00 2001 From: Siva Rama Krishna Date: Wed, 11 Feb 2026 15:21:43 +0530 Subject: [PATCH] feat:enhance subscription management and context removal in AngularPConnectService --- .../src/lib/_bridge/angular-pconnect.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/angular-sdk-components/src/lib/_bridge/angular-pconnect.ts b/packages/angular-sdk-components/src/lib/_bridge/angular-pconnect.ts index 7d557824..dfa5762e 100644 --- a/packages/angular-sdk-components/src/lib/_bridge/angular-pconnect.ts +++ b/packages/angular-sdk-components/src/lib/_bridge/angular-pconnect.ts @@ -88,7 +88,17 @@ export class AngularPConnectService { let fnUnsubscribe; // console.log( `Bridge subscribing: ${theCompName} `); if (inComp) { - fnUnsubscribe = this.getStore().subscribe(inCallback); + let bSubscribed = true; + const wrappedCallback = () => { + if (bSubscribed && inCallback) { + inCallback(); + } + }; + const storeUnsubscribe = this.getStore().subscribe(wrappedCallback); + fnUnsubscribe = () => { + bSubscribed = false; + storeUnsubscribe(); + }; } return fnUnsubscribe; } @@ -283,6 +293,28 @@ export class AngularPConnectService { if (inComp.pConn$?.removeFormField) { inComp.pConn$?.removeFormField(); } + + const contextName = inComp.pConn$.getContextName(); + const pageReference = inComp.pConn$.getPageReference(); + const rawConfig = inComp.pConn$._rawConfig; + const index = inComp.pConn$.index; + + if (Object.hasOwn(rawConfig?.config ?? {}, 'value') && inComp.pConn$._type !== 'Address') { + PCore.getContextTreeManager().removeFieldNode( + contextName, + pageReference, + inComp.pConn$.viewName || '', + inComp.pConn$._getPropertyName(), + index as number + ); + } else if (inComp.pConn$._type === 'Address' && rawConfig?.config?.associatedView) { + // remove address node and its children + PCore.getContextTreeManager().removeViewNode(contextName, pageReference, rawConfig.config.associatedView, index as number); + } else { + // remove view node and its children + const pageRef = rawConfig?.config?.context ? `${pageReference}${rawConfig?.config.context}` : pageReference; + PCore.getContextTreeManager().removeViewNode(contextName, pageRef, rawConfig?.config?.name || rawConfig?.config?.id || '', index); + } } // Returns true if the component's entry in ___componentPropsArr___ is