Skip to content

Commit cd0775c

Browse files
SCAL-255929 - Added cleanup event on destroy
1 parent cb0605f commit cd0775c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/embed/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const CONFIG_DEFAULTS: Partial<EmbedConfig> = {
4141
authTriggerText: 'Authorize',
4242
authType: AuthType.None,
4343
logLevel: LogLevel.ERROR,
44+
waitForCleanupOnDestroy: false,
45+
cleanupTimeout: 5000,
4446
};
4547

4648
export interface executeTMLInput {

src/embed/ts-embed.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,20 @@ export class TsEmbed {
13961396
public destroy(): void {
13971397
try {
13981398
this.removeFullscreenChangeHandler();
1399-
this.insertedDomEl?.parentNode.removeChild(this.insertedDomEl);
14001399
this.unsubscribeToEvents();
1400+
if (!getEmbedConfig().waitForCleanupOnDestroy) {
1401+
this.trigger(HostEvent.DestroyEmbed)
1402+
this.insertedDomEl?.parentNode?.removeChild(this.insertedDomEl);
1403+
} else {
1404+
const cleanupTimeout = getEmbedConfig().cleanupTimeout;
1405+
setTimeout(() => {
1406+
this.trigger(HostEvent.DestroyEmbed).then(() => {
1407+
this.insertedDomEl?.parentNode?.removeChild(this.insertedDomEl);
1408+
}).catch((e) => {
1409+
logger.log('Error destroying TS Embed', e);
1410+
});
1411+
}, cleanupTimeout);
1412+
}
14011413
} catch (e) {
14021414
logger.log('Error destroying TS Embed', e);
14031415
}

src/types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,19 @@ export interface EmbedConfig {
692692
* ```
693693
*/
694694
customActions?: CustomAction[];
695+
696+
/**
697+
* Wait for the cleanup to be completed before destroying the embed.
698+
* @version SDK: 1.41.0 | ThoughtSpot: 10.12.0.cl
699+
* @default false
700+
*/
701+
waitForCleanupOnDestroy?: boolean;
702+
/**
703+
* The timeout for the cleanup to be completed before destroying the embed.
704+
* @version SDK: 1.41.0 | ThoughtSpot: 10.12.0.cl
705+
* @default 10000
706+
*/
707+
cleanupTimeout?: number;
695708
}
696709

697710
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -4247,6 +4260,15 @@ export enum HostEvent {
42474260
* ```
42484261
*/
42494262
UpdateEmbedParams = 'updateEmbedParams',
4263+
/**
4264+
* Triggered when the embed is needed to be destroyed. This is used to clean up any embed related resources internally.
4265+
* @example
4266+
* ```js
4267+
* liveboardEmbed.trigger(HostEvent.DestroyEmbed);
4268+
* ```
4269+
* @version SDK: 1.41.0 | ThoughtSpot: 10.12.0.cl
4270+
*/
4271+
DestroyEmbed = 'EmbedDestroyed',
42504272
}
42514273

42524274
/**

0 commit comments

Comments
 (0)