Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/config/nav-menu/all-nav-items.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const allNavItems: {[key: string]: NavMenuItem} = {
},
blog: {
label: 'Blog',
url: getMarketingUrl('/blog/all-posts'),
url: getMarketingUrl('/blog'),
},
bookADemo: {
label: 'Book a Demo',
Expand Down
26 changes: 25 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type NavigationAppProps = {
integrations?: {[key: string]: 'disable'}
}

export type TcUniNavMethods = 'init' | 'update' | 'triggerFlow'
export type TcUniNavMethods = 'init' | 'update' | 'destroy' | 'triggerFlow'

export type TcUniNavFn = (
method: TcUniNavMethods,
Expand All @@ -54,6 +54,26 @@ const NavigationLoadersMap = {

const instancesContextStore: { [key: string]: Map<string, Writable<any>> } = {}

async function destroy(
targetId: string,
) {
if (Object.prototype.hasOwnProperty.call(instancesContextStore, targetId)) {
delete instancesContextStore[targetId];
}

if (typeof targetId !== 'string') {
throw new Error(`'targetId' should be a string`);
}

const targetEl: Element | null = document.getElementById(targetId);

if (targetEl?.nodeType !== Node.ELEMENT_NODE) {
throw new Error(`[TcUnivNav] 'target' must be a valid dom element with an id of #${targetId}!`);
}

targetEl.innerHTML = '';
}

/**
* Initialize the navigation component
* @param targetId Target element ID
Expand Down Expand Up @@ -161,6 +181,10 @@ function execQueueCall(method: TcUniNavMethods, ...args: any[]) {
triggerFlow.call(null, ...args)
}

else if (method === 'destroy') {
destroy.call(null, ...args);
}

else if (method === 'trigger') {
appPubSub.publish.call(appPubSub, ...args);
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export declare type NavigationAppProps = {
[key: string]: 'disable';
};
};
export declare type TcUniNavMethods = 'init' | 'update' | 'triggerFlow';
export declare type TcUniNavMethods = 'init' | 'update' | 'destroy' | 'triggerFlow';
export declare type TcUniNavFn = (method: TcUniNavMethods, targetId: string, config: NavigationAppProps) => void;