-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lazyLoad): Allow
loadChildren:
sugar on a state definition
feat(lazyLoad): automatically unwrap default export (`__esModule`) (allows easier default export of NgModule) fix(lazyLoad): Update lazyLoad for ui-router-core 3.1 Instead of: ```js import { loadNgModule } from "ui-router-ng2"; var futureState = { name: 'lazy.state', url: '/lazy', lazyLoad: loadNgModule('./lazy/lazy.module') } ``` Instead of: ```js import { loadNgModule } from "ui-router-ng2"; var futureState = { name: 'lazy.state', url: '/lazy', lazyLoad: loadNgModule(() => System.import('./lazy/lazy.module').then(result => result.LazyModule)) } ``` Switch to: ```js var futureState = { name: 'lazy.state.**', url: '/lazy', loadChildren: './lazy/lazy.module#LazyModule' } ``` --- This change is an incremental step towards seamless AoT and lazy load support within the angular-cli. Currently the cli only supports lazy loading of angular router routes. We expect the AoT compiler and cli (@ngtools/webpack) will be updated to support AoT lazy loading by other routers (such as ui-router) soon.
- Loading branch information
1 parent
82a52e5
commit 2a4b174
Showing
8 changed files
with
212 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** @module ng2 */ | ||
/** */ | ||
import { LazyLoadResult, Transition, StateDeclaration } from "ui-router-core"; // has or is using | ||
import { BuilderFunction, State } from "ui-router-core"; | ||
import { loadNgModule } from "../lazyLoad/lazyLoadNgModule"; | ||
|
||
/** | ||
* This is a [[StateBuilder.builder]] function for ngModule lazy loading in angular2. | ||
* | ||
* When the [[StateBuilder]] builds a [[State]] object from a raw [[StateDeclaration]], this builder | ||
* decorates the `lazyLoad` property for states that have a [[Ng2StateDeclaration.ngModule]] declaration. | ||
* | ||
* If the state has a [[Ng2StateDeclaration.ngModule]], it will create a `lazyLoad` function | ||
* that in turn calls `loadNgModule(loadNgModuleFn)`. | ||
* | ||
* #### Example: | ||
* A state that has a `ngModule` | ||
* ```js | ||
* var decl = { | ||
* ngModule: () => System.import('./childModule.ts') | ||
* } | ||
* ``` | ||
* would build a state with a `lazyLoad` function like: | ||
* ```js | ||
* import { loadNgModule } from "ui-router-ng2"; | ||
* var decl = { | ||
* lazyLoad: loadNgModule(() => System.import('./childModule.ts') | ||
* } | ||
* ``` | ||
* | ||
* If the state has both a `ngModule:` *and* a `lazyLoad`, then the `lazyLoad` is run first. | ||
* | ||
* #### Example: | ||
* ```js | ||
* var decl = { | ||
* lazyLoad: () => System.import('third-party-library'), | ||
* ngModule: () => System.import('./childModule.ts') | ||
* } | ||
* ``` | ||
* would build a state with a `lazyLoad` function like: | ||
* ```js | ||
* import { loadNgModule } from "ui-router-ng2"; | ||
* var decl = { | ||
* lazyLoad: () => System.import('third-party-library') | ||
* .then(() => loadNgModule(() => System.import('./childModule.ts')) | ||
* } | ||
* ``` | ||
* | ||
*/ | ||
export function ng2LazyLoadBuilder(state: State, parent: BuilderFunction) { | ||
let loadNgModuleFn = state['loadChildren']; | ||
return loadNgModuleFn ? loadNgModule(loadNgModuleFn) : state.lazyLoad; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters