Skip to content

Commit

Permalink
feat(lazyLoad): Remove NgModuleToLoad type (string based lazy module …
Browse files Browse the repository at this point in the history
…loading)

BREAKING CHANGE: Removed string based lazy module loading via loadChildren
Previously, we supported `loadChildren: './lazymodule/lazy.module.ts#LazyModule'`
This lazy load mechanism is deprecated in Angular 8 in favor of:
`loadChildren: import('./lazymodule/lazy.module).then(x => x.LazyModule)`

Migrate your `loadChildren`(s) to the `import()` style.
  • Loading branch information
christopherthielen committed Nov 11, 2019
1 parent 5b672ea commit 2f1506c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { StateDeclaration, _ViewDeclaration, Transition, HookResult } from '@uirouter/core';
import { Type, Component } from '@angular/core';
import { NgModuleToLoad } from './lazyLoad/lazyLoadNgModule';
import { ModuleTypeCallback } from './lazyLoad/lazyLoadNgModule';

/**
* The StateDeclaration object is used to define a state or nested state.
Expand Down Expand Up @@ -155,7 +155,7 @@ export interface Ng2StateDeclaration extends StateDeclaration, Ng2ViewDeclaratio
* }
* ```
*/
loadChildren?: NgModuleToLoad;
loadChildren?: ModuleTypeCallback;
}

export interface Ng2ViewDeclaration extends _ViewDeclaration {
Expand Down
19 changes: 5 additions & 14 deletions src/lazyLoad/lazyLoadNgModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ import { applyModuleConfig } from '../uiRouterConfig';
* ```
*/
export type ModuleTypeCallback = () => Type<any> | Promise<Type<any>>;
/**
* A string or a function which lazy loads a module
*
* If a string, should conform to the Angular Router `loadChildren` string.
* #### Example:
* ```
* var ngModuleToLoad = './foo/foo.module#FooModule'
* ```
*
* For functions, see: [[ModuleTypeCallback]]
*/
export type NgModuleToLoad = string | ModuleTypeCallback;

/**
* Returns a function which lazy loads a nested module
Expand Down Expand Up @@ -81,7 +69,7 @@ export type NgModuleToLoad = string | ModuleTypeCallback;
* - Returns the new states array
*/
export function loadNgModule(
moduleToLoad: NgModuleToLoad
moduleToLoad: ModuleTypeCallback
): (transition: Transition, stateObject: StateDeclaration) => Promise<LazyLoadResult> {
return (transition: Transition, stateObject: StateDeclaration) => {
const ng2Injector = transition.injector().get(NATIVE_INJECTOR_TOKEN);
Expand Down Expand Up @@ -109,7 +97,10 @@ export function loadNgModule(
*
* @internalapi
*/
export function loadModuleFactory(moduleToLoad: NgModuleToLoad, ng2Injector: Injector): Promise<NgModuleFactory<any>> {
export function loadModuleFactory(
moduleToLoad: ModuleTypeCallback,
ng2Injector: Injector
): Promise<NgModuleFactory<any>> {
if (isString(moduleToLoad)) {
return ng2Injector.get(NgModuleFactoryLoader).load(moduleToLoad);
}
Expand Down

0 comments on commit 2f1506c

Please sign in to comment.