Skip to content

Commit

Permalink
fix(aot): allow to build with AOT compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malkevich committed Mar 18, 2019
1 parent 2ac94b2 commit a7771c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
25 changes: 18 additions & 7 deletions projects/dynamic-menu/src/lib/dynamic-menu-extras.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InjectionToken, Provider } from '@angular/core';
import { Inject, Injectable, InjectionToken, Provider } from '@angular/core';

/**
* Extra configuration for {@link DynamicMenuModule}
Expand All @@ -19,19 +19,30 @@ export interface DynamicMenuExtras {
* DI token that hold extra configuration
* @internal
*/
export class DynamicMenuExtrasToken implements DynamicMenuExtras {
constructor(public listenForConfigChanges = false) {}
export const DynamicMenuExtrasToken = new InjectionToken<DynamicMenuExtras>(
'DynamicMenuExtrasToken',
);

/**
* @internal
*/
@Injectable({ providedIn: 'root' })
export class DynamicMenuExtrasService implements DynamicMenuExtras {
listenForConfigChanges = this.extras.listenForConfigChanges;

constructor(
@Inject(DynamicMenuExtrasToken)
private extras: DynamicMenuExtras = { listenForConfigChanges: false },
) {}
}

/**
* Helper function to provide {@link DYNAMIC_MENU_EXTRAS_TOKEN}
* @internal
*/
export function provideDynamicMenuExtras(
extras: DynamicMenuExtras = {},
): Provider {
export function provideDynamicMenuExtras(extras?: DynamicMenuExtras): Provider {
return {
provide: DynamicMenuExtrasToken,
useValue: new DynamicMenuExtrasToken(extras.listenForConfigChanges),
useValue: extras,
};
}
6 changes: 3 additions & 3 deletions projects/dynamic-menu/src/lib/dynamic-menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
takeUntil,
} from 'rxjs/operators';

import { DynamicMenuExtrasToken } from './dynamic-menu-extras';
import { DynamicMenuExtrasService } from './dynamic-menu-extras';
import { DYNAMIC_MENU_ROUTES_TOKEN } from './dynamic-menu-routes';
import { SUB_MENU_MAP_TOKEN, SubMenuMap } from './sub-menu-map-provider';
import {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class DynamicMenuService implements OnDestroy {
refCount(),
);

private configChanged$ = this.dynamicMenuExtrasToken.listenForConfigChanges
private configChanged$ = this.dynamicMenuExtrasService.listenForConfigChanges
? this.router.events.pipe(filter(e => e instanceof RouteConfigLoadEnd))
: EMPTY;

Expand Down Expand Up @@ -103,7 +103,7 @@ export class DynamicMenuService implements OnDestroy {
constructor(
private injector: Injector,
private router: Router,
private dynamicMenuExtrasToken: DynamicMenuExtrasToken,
private dynamicMenuExtrasService: DynamicMenuExtrasService,
) {
this.dynamicMenu$.pipe(takeUntil(this.destroyed$)).subscribe();
}
Expand Down

0 comments on commit a7771c0

Please sign in to comment.