Skip to content

Commit 66169c7

Browse files
SCAL-255929 - Added cleanup event on destroy
1 parent 56ebcd8 commit 66169c7

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-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
@@ -1328,8 +1328,20 @@ export class TsEmbed {
13281328
public destroy(): void {
13291329
try {
13301330
this.removeFullscreenChangeHandler();
1331-
this.insertedDomEl?.parentNode.removeChild(this.insertedDomEl);
13321331
this.unsubscribeToEvents();
1332+
if (!getEmbedConfig().waitForCleanupOnDestroy) {
1333+
this.trigger(HostEvent.DestroyEmbed)
1334+
this.insertedDomEl?.parentNode?.removeChild(this.insertedDomEl);
1335+
} else {
1336+
const cleanupTimeout = getEmbedConfig().cleanupTimeout;
1337+
setTimeout(() => {
1338+
this.trigger(HostEvent.DestroyEmbed).then(() => {
1339+
this.insertedDomEl?.parentNode?.removeChild(this.insertedDomEl);
1340+
}).catch((e) => {
1341+
logger.log('Error destroying TS Embed', e);
1342+
});
1343+
}, cleanupTimeout);
1344+
}
13331345
} catch (e) {
13341346
logger.log('Error destroying TS Embed', e);
13351347
}

src/types.ts

Lines changed: 23 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
@@ -4169,6 +4182,16 @@ export enum HostEvent {
41694182
* @version SDK: 1.41.0 | ThoughtSpot: 10.12.0.cl
41704183
*/
41714184
AskSpotter = 'AskSpotter',
4185+
4186+
/**
4187+
* Triggered when the embed is needed to be destroyed. This is used to clean up any embed related resources internally.
4188+
* @example
4189+
* ```js
4190+
* liveboardEmbed.trigger(HostEvent.DestroyEmbed);
4191+
* ```
4192+
* @version SDK: 1.41.0 | ThoughtSpot: 10.12.0.cl
4193+
*/
4194+
DestroyEmbed = 'EmbedDestroyed',
41724195
}
41734196

41744197
/**

0 commit comments

Comments
 (0)