Skip to content

Commit 03f9beb

Browse files
committed
Updated documentation for loadComponent functionality
1 parent 5ef4430 commit 03f9beb

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/lazyLoad/lazyLoadNgModule.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,16 @@ export type ModuleTypeCallback<T = unknown> = () => Type<T> | Promise<Type<T>>;
3636
* It could also be used manually as a [[StateDeclaration.lazyLoad]] property to lazy load an `NgModule` and its state(s).
3737
*
3838
* #### Example:
39-
* Using `import()` and named export of `HomeModule`
40-
* ```js
41-
* declare var System;
39+
* ```ts
4240
* var futureState = {
4341
* name: 'home.**',
4442
* url: '/home',
4543
* lazyLoad: loadNgModule(() => import('./home/home.module').then(result => result.HomeModule))
4644
* }
4745
* ```
4846
*
49-
* #### Example:
50-
* Using a path (string) to the module
51-
* ```js
52-
* var futureState = {
53-
* name: 'home.**',
54-
* url: '/home',
55-
* lazyLoad: loadNgModule('./home/home.module#HomeModule')
56-
* }
57-
* ```
58-
*
5947
*
60-
* @param moduleToLoad a path (string) to the NgModule to load.
61-
* Or a function which loads the NgModule code which should
48+
* @param moduleToLoad function which loads the NgModule code which should
6249
* return a reference to the `NgModule` class being loaded (or a `Promise` for it).
6350
*
6451
* @returns A function which takes a transition, which:
@@ -203,6 +190,26 @@ export function multiProviderParentChildDelta<T>(parent: Injector, child: Inject
203190
*/
204191
export type ComponentTypeCallback<T> = ModuleTypeCallback<T>;
205192

193+
/**
194+
* Returns a function which lazy loads a standalone component for the target state
195+
*
196+
* #### Example:
197+
* ```ts
198+
* var futureComponentState = {
199+
* name: 'home',
200+
* url: '/home',
201+
* lazyLoad: loadComponent(() => import('./home.component').then(result => result.HomeComponent))
202+
* }
203+
* ```
204+
*
205+
* @param callback function which loads the Component code which should
206+
* return a reference to the `Component` class being loaded (or a `Promise` for it).
207+
*
208+
* @returns A function which takes a transition, stateObject, and:
209+
* - Loads a standalone component
210+
* - replaces the component configuration of the stateObject.
211+
* - Returns the new states array
212+
*/
206213
export function loadComponent<T>(
207214
callback: ComponentTypeCallback<T>
208215
): (transition: Transition, stateObject: Ng2StateDeclaration) => Promise<LazyLoadResult> {
@@ -215,18 +222,22 @@ export function loadComponent<T>(
215222
}
216223

217224
/**
225+
* Apply the lazy-loaded component to the stateObject.
226+
*
218227
* @internal
219-
* @param component
220-
* @param transition
221-
* @param stateObject
228+
* @param component reference to the component class
229+
* @param transition Transition object reference
230+
* @param stateObject target state configuration object
231+
*
232+
* @returns the new states array
222233
*/
223234
export function applyComponent<T>(
224235
component: Type<T>,
225236
transition: Transition,
226237
stateObject: Ng2StateDeclaration
227238
): LazyLoadResult {
228239

229-
if (!isStandalone(component)) throw _notStandaloneError();
240+
if (!isStandalone(component)) throw new Error("Is not a standalone component.");
230241

231242
const registry = transition.router.stateRegistry;
232243
const current = stateObject.component;
@@ -236,7 +247,3 @@ export function applyComponent<T>(
236247

237248
return { states: [stateObject, ...children] }
238249
}
239-
240-
function _notStandaloneError(): Error {
241-
return new Error("Is not standalone.");
242-
}

0 commit comments

Comments
 (0)