Skip to content

Commit ece8433

Browse files
artlowelatarix83
authored andcommitted
replace menu decorators with switches to solve an issue where decorators were not loaded in time
1 parent 9f22324 commit ece8433

9 files changed

Lines changed: 26 additions & 57 deletions

File tree

src/app/+admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, Inject, Injector, OnInit } from '@angular/core';
22
import { MenuSectionComponent } from '../../../shared/menu/menu-section/menu-section.component';
33
import { MenuID } from '../../../shared/menu/initial-menus-state';
44
import { MenuService } from '../../../shared/menu/menu.service';
5-
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
65
import { LinkMenuItemModel } from '../../../shared/menu/menu-item/models/link.model';
76
import { MenuSection } from '../../../shared/menu/menu.reducer';
87

@@ -15,7 +14,6 @@ import { MenuSection } from '../../../shared/menu/menu.reducer';
1514
styleUrls: ['./admin-sidebar-section.component.scss'],
1615

1716
})
18-
@rendersSectionForMenu(MenuID.ADMIN, false)
1917
export class AdminSidebarSectionComponent extends MenuSectionComponent implements OnInit {
2018

2119
/**

src/app/+admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { MenuID } from '../../../shared/menu/initial-menus-state';
88
import { MenuService } from '../../../shared/menu/menu.service';
99
import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
1010
import { map } from 'rxjs/operators';
11-
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
1211

1312
/**
1413
* Represents a expandable section in the sidebar
@@ -20,7 +19,6 @@ import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorat
2019
animations: [rotate, slide, bgColor]
2120
})
2221

23-
@rendersSectionForMenu(MenuID.ADMIN, true)
2422
export class ExpandableAdminSidebarSectionComponent extends AdminSidebarSectionComponent implements OnInit {
2523
/**
2624
* This section resides in the Admin Sidebar

src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { MenuID } from '../../shared/menu/initial-menus-state';
55
import { slide } from '../../shared/animations/slide';
66
import { first } from 'rxjs/operators';
77
import { HostWindowService } from '../../shared/host-window.service';
8-
import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator';
98

109
/**
1110
* Represents an expandable section in the navbar
@@ -16,7 +15,6 @@ import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator'
1615
styleUrls: ['./expandable-navbar-section.component.scss'],
1716
animations: [slide]
1817
})
19-
@rendersSectionForMenu(MenuID.PUBLIC, true)
2018
export class ExpandableNavbarSectionComponent extends NavbarSectionComponent implements OnInit {
2119
/**
2220
* This section resides in the Public Navbar

src/app/navbar/navbar-section/navbar-section.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component, Inject, Injector, OnInit } from '@angular/core';
22
import { MenuSectionComponent } from '../../shared/menu/menu-section/menu-section.component';
33
import { MenuService } from '../../shared/menu/menu.service';
44
import { MenuID } from '../../shared/menu/initial-menus-state';
5-
import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator';
65

76
/**
87
* Represents a non-expandable section in the navbar
@@ -12,7 +11,6 @@ import { rendersSectionForMenu } from '../../shared/menu/menu-section.decorator'
1211
templateUrl: './navbar-section.component.html',
1312
styleUrls: ['./navbar-section.component.scss']
1413
})
15-
@rendersSectionForMenu(MenuID.PUBLIC, false)
1614
export class NavbarSectionComponent extends MenuSectionComponent implements OnInit {
1715
/**
1816
* This section resides in the Public Navbar
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import { MenuItemType } from './initial-menus-state';
2-
3-
const menuMenuItemComponentMap = new Map();
4-
5-
/**
6-
* Decorator function to link a MenuItemType to a Component
7-
* @param {MenuItemType} type The MenuItemType of the MenuSection's model
8-
* @returns {(sectionComponent: GenericContructor) => void}
9-
*/
10-
export function rendersMenuItemForType(type: MenuItemType) {
11-
return function decorator(sectionComponent: any) {
12-
if (!sectionComponent) {
13-
return;
14-
}
15-
menuMenuItemComponentMap.set(type, sectionComponent);
16-
};
17-
}
2+
import { LinkMenuItemComponent } from './menu-item/link-menu-item.component';
3+
import { OnClickMenuItemComponent } from './menu-item/onclick-menu-item.component';
4+
import { TextMenuItemComponent } from './menu-item/text-menu-item.component';
185

196
/**
207
* Retrieves the Component matching a given MenuItemType
218
* @param {MenuItemType} type The given MenuItemType
229
* @returns {GenericConstructor} The constructor of the Component that matches the MenuItemType
2310
*/
2411
export function getComponentForMenuItemType(type: MenuItemType) {
25-
return menuMenuItemComponentMap.get(type);
12+
switch (type) {
13+
case MenuItemType.LINK:
14+
return LinkMenuItemComponent;
15+
case MenuItemType.ONCLICK:
16+
return OnClickMenuItemComponent;
17+
case MenuItemType.TEXT:
18+
return TextMenuItemComponent;
19+
}
2620
}

src/app/shared/menu/menu-item/link-menu-item.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { Component, Inject, Input, OnInit } from '@angular/core';
1+
import { Component, Inject, OnInit } from '@angular/core';
22
import { LinkMenuItemModel } from './models/link.model';
3-
import { MenuItemType } from '../initial-menus-state';
4-
import { rendersMenuItemForType } from '../menu-item.decorator';
53
import { isNotEmpty } from '../../empty.util';
64
import { environment } from '../../../../environments/environment';
75

@@ -12,7 +10,6 @@ import { environment } from '../../../../environments/environment';
1210
selector: 'ds-link-menu-item',
1311
templateUrl: './link-menu-item.component.html'
1412
})
15-
@rendersMenuItemForType(MenuItemType.LINK)
1613
export class LinkMenuItemComponent implements OnInit {
1714
item: LinkMenuItemModel;
1815
hasLink: boolean;

src/app/shared/menu/menu-item/onclick-menu-item.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Component, Inject } from '@angular/core';
2-
import { MenuItemType } from '../initial-menus-state';
3-
import { rendersMenuItemForType } from '../menu-item.decorator';
42
import { OnClickMenuItemModel } from './models/onclick.model';
53

64
/**
@@ -11,7 +9,6 @@ import { OnClickMenuItemModel } from './models/onclick.model';
119
styleUrls: ['./onclick-menu-item.component.scss'],
1210
templateUrl: './onclick-menu-item.component.html'
1311
})
14-
@rendersMenuItemForType(MenuItemType.ONCLICK)
1512
export class OnClickMenuItemComponent {
1613
item: OnClickMenuItemModel;
1714
constructor(@Inject('itemModelProvider') item: OnClickMenuItemModel) {

src/app/shared/menu/menu-item/text-menu-item.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { Component, Inject, Input } from '@angular/core';
1+
import { Component, Inject } from '@angular/core';
22
import { TextMenuItemModel } from './models/text.model';
3-
import { MenuItemType } from '../initial-menus-state';
4-
import { rendersMenuItemForType } from '../menu-item.decorator';
53

64
/**
75
* Component that renders a menu section of type TEXT
@@ -10,7 +8,6 @@ import { rendersMenuItemForType } from '../menu-item.decorator';
108
selector: 'ds-text-menu-item',
119
templateUrl: './text-menu-item.component.html',
1210
})
13-
@rendersMenuItemForType(MenuItemType.TEXT)
1411
export class TextMenuItemComponent {
1512
item: TextMenuItemModel;
1613
constructor(@Inject('itemModelProvider') item: TextMenuItemModel) {
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
import { MenuID } from './initial-menus-state';
2-
3-
const menuComponentMap = new Map();
4-
5-
/**
6-
* Decorator function to render a MenuSection for a menu
7-
* @param {MenuID} menuID The ID of the Menu in which the section is rendered
8-
* @param {boolean} expandable True when the section should be expandable, false when if should not
9-
* @returns {(menuSectionWrapperComponent: GenericConstructor) => void}
10-
*/
11-
export function rendersSectionForMenu(menuID: MenuID, expandable: boolean) {
12-
return function decorator(menuSectionWrapperComponent: any) {
13-
if (!menuSectionWrapperComponent) {
14-
return;
15-
}
16-
if (!menuComponentMap.get(menuID)) {
17-
menuComponentMap.set(menuID, new Map());
18-
}
19-
menuComponentMap.get(menuID).set(expandable, menuSectionWrapperComponent);
20-
};
21-
}
2+
import { NavbarSectionComponent } from '../../navbar/navbar-section/navbar-section.component';
3+
import { ExpandableNavbarSectionComponent } from '../../navbar/expandable-navbar-section/expandable-navbar-section.component';
4+
import { ExpandableAdminSidebarSectionComponent } from '../../+admin/admin-sidebar/expandable-admin-sidebar-section/expandable-admin-sidebar-section.component';
5+
import { AdminSidebarSectionComponent } from '../../+admin/admin-sidebar/admin-sidebar-section/admin-sidebar-section.component';
226

237
/**
248
* Retrieves the component matching the given MenuID and whether or not it should be expandable
@@ -27,5 +11,13 @@ export function rendersSectionForMenu(menuID: MenuID, expandable: boolean) {
2711
* @returns {GenericConstructor} The constructor of the matching Component
2812
*/
2913
export function getComponentForMenu(menuID: MenuID, expandable: boolean) {
30-
return menuComponentMap.get(menuID).get(expandable);
14+
if (menuID === MenuID.PUBLIC && expandable === true) {
15+
return ExpandableNavbarSectionComponent;
16+
} else if (menuID === MenuID.PUBLIC && expandable === false) {
17+
return NavbarSectionComponent;
18+
} else if (menuID === MenuID.ADMIN && expandable === true) {
19+
return ExpandableAdminSidebarSectionComponent;
20+
} else if (menuID === MenuID.ADMIN && expandable === false) {
21+
return AdminSidebarSectionComponent;
22+
}
3123
}

0 commit comments

Comments
 (0)