[DURACOM-191] set static map for menu-item decorator

This commit is contained in:
Andrea Barbasso
2024-01-15 12:13:14 +01:00
parent 4cab7a31af
commit 2d3c5cef06
5 changed files with 8 additions and 28 deletions

View File

@@ -1,20 +1,12 @@
import { MenuItemType } from './menu-item-type.model';
import { defer } from 'rxjs';
const menuMenuItemComponentMap = new Map();
/**
* Decorator function to link a MenuItemType to a Component
* @param {MenuItemType} type The MenuItemType of the MenuSection's model
* @returns {(sectionComponent: GenericContructor) => void}
*/
export function rendersMenuItemForType(type: MenuItemType) {
return function decorator(sectionComponent: any) {
if (!sectionComponent) {
return;
}
menuMenuItemComponentMap.set(type, sectionComponent);
};
}
const menuMenuItemComponentMap = {
[MenuItemType.EXTERNAL]: defer(() => import('./menu-item/external-link-menu-item.component').then(m => m.ExternalLinkMenuItemComponent)),
[MenuItemType.LINK]: defer(() => import('./menu-item/link-menu-item.component').then(m => m.LinkMenuItemComponent)),
[MenuItemType.ONCLICK]: defer(() => import('./menu-item/onclick-menu-item.component').then(m => m.OnClickMenuItemComponent)),
[MenuItemType.TEXT]: defer(() => import('./menu-item/text-menu-item.component').then(m => m.TextMenuItemComponent))
};
/**
* Retrieves the Component matching a given MenuItemType
@@ -22,5 +14,5 @@ export function rendersMenuItemForType(type: MenuItemType) {
* @returns {GenericConstructor} The constructor of the Component that matches the MenuItemType
*/
export function getComponentForMenuItemType(type: MenuItemType) {
return menuMenuItemComponentMap.get(type);
return menuMenuItemComponentMap[type];
}