Skip to content

Commit

Permalink
refactor(types): move from service to types
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malkevich committed Feb 26, 2019
1 parent b406c06 commit a9600a3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
7 changes: 2 additions & 5 deletions projects/dynamic-menu/src/lib/dynamic-menu.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import { takeUntil } from 'rxjs/operators';

import { provideDynamicMenuExtras } from './dynamic-menu-extras';
import { provideDynamicMenuRoutes } from './dynamic-menu-routes';
import {
DynamicMenuRouteConfig,
DynamicMenuService,
} from './dynamic-menu.service';
import { DynamicMenuService } from './dynamic-menu.service';
import { provideSubMenuMap } from './sub-menu-map-provider';
import { RoutesWithMenu } from './types';
import { DynamicMenuRouteConfig, RoutesWithMenu } from './types';

@Component({ selector: 'ndm-test', template: '' })
class TestComponent {}
Expand Down
28 changes: 7 additions & 21 deletions projects/dynamic-menu/src/lib/dynamic-menu.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Injector, Type } from '@angular/core';
import { Injectable, Injector } from '@angular/core';
import { Route, RouteConfigLoadEnd, Router } from '@angular/router';
import { EMPTY, zip } from 'rxjs';
import {
Expand All @@ -13,26 +13,12 @@ import {
import { DynamicMenuExtrasToken } 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 { DataWithMenu, MenuItem, RoutesWithMenu, RouteWithMenu } from './types';

export interface DynamicMenuItem extends MenuItem {
children: DynamicMenuRouteConfig[];
}

export interface DynamicDataWithMenu extends DataWithMenu {
menu: DynamicMenuItem;
}

export interface DynamicMenuRouteConfig extends RouteWithMenu {
data: DynamicDataWithMenu;
fullUrl: string[];
subMenuComponent?: Type<any> | string;
}

export type DynamicMenuConfigFn = (
config: DynamicMenuRouteConfig,
parentConfig?: DynamicMenuRouteConfig,
) => DynamicMenuRouteConfig;
import {
DynamicMenuConfigFn,
DynamicMenuRouteConfig,
RoutesWithMenu,
RouteWithMenu,
} from './types';

@Injectable({
providedIn: 'root',
Expand Down
2 changes: 1 addition & 1 deletion projects/dynamic-menu/src/lib/dynamic-menu/context-item.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TemplateRef } from '@angular/core';

import { DynamicMenuRouteConfig } from '../dynamic-menu.service';
import { DynamicMenuRouteConfig } from '../types';
import { DynamicMenuTemplateContext } from './context-template';

export class DynamicMenuItemContext extends DynamicMenuTemplateContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TemplateRef } from '@angular/core';

import { DynamicMenuRouteConfig } from '../dynamic-menu.service';
import { DynamicMenuRouteConfig } from '../types';
import { DynamicMenuItemContext } from './context-item';

export class DynamicMenuToggleContext extends DynamicMenuItemContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TemplateRef } from '@angular/core';

import { DynamicMenuRouteConfig } from '../dynamic-menu.service';
import { DynamicMenuRouteConfig } from '../types';
import { DynamicMenuTemplateContext } from './context-template';

export class DynamicMenuWrapperContext extends DynamicMenuTemplateContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
import { EMPTY, Observable, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import {
DynamicMenuRouteConfig,
DynamicMenuService,
} from '../dynamic-menu.service';
import { DynamicMenuService } from '../dynamic-menu.service';
import { DynamicMenuRouteConfig } from '../types';
import { DynamicMenuItemContext } from './context-item';
import { DynamicMenuToggleContext } from './context-toggle';
import { DynamicMenuWrapperContext } from './context-wrapper';
Expand Down Expand Up @@ -53,6 +51,7 @@ export class DynamicMenuComponent implements OnInit, OnDestroy {

ngOnDestroy(): void {
this.destroyed$.next();
this.ctxCache.clear();
}

getWrapperCtx(configs: DynamicMenuRouteConfig[], tpl: TemplateRef<any>) {
Expand Down
19 changes: 19 additions & 0 deletions projects/dynamic-menu/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,22 @@ export interface RouteWithMenu extends Route {
}

export interface RoutesWithMenu extends Array<RouteWithMenu> {}

export interface DynamicMenuItem extends MenuItem {
children: DynamicMenuRouteConfig[];
}

export interface DynamicDataWithMenu extends DataWithMenu {
menu: DynamicMenuItem;
}

export interface DynamicMenuRouteConfig extends RouteWithMenu {
data: DynamicDataWithMenu;
fullUrl: string[];
subMenuComponent?: Type<any> | string;
}

export type DynamicMenuConfigFn = (
config: DynamicMenuRouteConfig,
parentConfig?: DynamicMenuRouteConfig,
) => DynamicMenuRouteConfig;

0 comments on commit a9600a3

Please sign in to comment.