You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(futureState): States with a .** name suffix (i.e., foo.**) are considered future states
- instead of states with a `lazyLoad` fn
feat(lazyLoad): Created `StateService.lazyLoad` method to imperatively lazy load a state
Closes#8
feat(lazyLoad): Exported/exposed the `lazyLoadState` function
- This can be used to manually trigger lazy loading of states.
feat(lazyLoad): the `lazyLoad` hook can be used to lazy load anything (component code, etc)
- Previously, `lazyLoad` was only used to load future states.
- Now, `lazyLoad` can be used to load anything.
- Previously, `lazyLoad` would forcibly de-register the future state.
- Now, `lazyLoad` does not deregister the future state.
- Now, the future state is deregistered when a normal state of the same name (without the .**) is registered.
Closes#4
BREAKING CHANGE:
Previously, a state with a `lazyLoad` function was considered a future state.
Now, a state whose name ends with `.**` (i.e., a glob pattern which matches all children) is a future state.
### All future states should be given a name that ends in `.**`.
Change your future states from:
```
{ name: 'future', url: '/future', lazyLoad: () => ... }
```
to:
```
{ name: 'future.**', url: '/future', lazyLoad: () => ... }
```
* If the promise resolves to an object with a `states: []` array,
521
-
* the lazy loaded states will be registered with the [[StateRegistry]].
522
-
* Generally, of the lazy loaded states should have the same name as the future state;
523
-
* then it will **replace the future state placeholder** in the registry.
524
+
* The `abcService` file is imported and loaded
525
+
* (it is assumed that the `abcService` file knows how to register itself as a service).
524
526
*
525
-
* In any case, when the promise successfully resolves, the placeholder Future State will be deregistered.
527
+
* #### Lifecycle
526
528
*
527
-
* #### `url`
529
+
* - The `lazyLoad` function is invoked if a transition is going to enter the state.
530
+
* - The function is invoked before the transition starts (using an `onBefore` transition hook).
531
+
* - The function is only invoked once; while the `lazyLoad` function is loading code, it will not be invoked again.
532
+
* For example, if the user double clicks a ui-sref, `lazyLoad` is only invoked once even though there were two transition attempts.
533
+
* Instead, the existing lazy load promise is re-used.
534
+
* - When the promise resolves successfully, the `lazyLoad` property is deleted from the state declaration.
535
+
* - If the promise resolves to a [[LazyLoadResult]] which has an array of `states`, those states are registered.
536
+
* - The original transition is retried (this time without the `lazyLoad` property present).
528
537
*
529
-
* A future state's `url` property acts as a wildcard.
538
+
* - If the `lazyLoad` function fails, then the transition also fails.
539
+
* The failed transition (and the `lazyLoad` function) could potentially be retried by the user.
530
540
*
531
-
* UI-Router matches all paths that begin with the `url`.
532
-
* It effectively appends `.*` to the internal regular expression.
541
+
* ### Lazy loading state definitions (Future States)
533
542
*
534
-
* #### `name`
543
+
* State definitions can also be lazy loaded.
544
+
* This might be desirable when building large, multi-module applications.
535
545
*
536
-
* A future state's `name` property acts as a wildcard.
546
+
* To lazy load state definitions, a Future State should be registered as a placeholder.
547
+
* When the state definitions are lazy loaded, the Future State is deregistered.
537
548
*
538
-
* It matches any state name that starts with the `name`.
539
-
* UI-Router effectively matches the future state using a `.**` [[Glob]] appended to the `name`.
549
+
* A future state can act as a placeholder for a single state, or for an entire module of states and substates.
550
+
* A future state should have:
540
551
*
541
-
* @example
542
-
* #### states.js
552
+
* - A `name` which ends in `.**`.
553
+
* A future state's `name` property acts as a wildcard [[Glob]].
554
+
* It matches any state name that starts with the `name` (including child states that are not yet loaded).
555
+
* - A `url` prefix.
556
+
* A future state's `url` property acts as a wildcard.
557
+
* UI-Router matches all paths that begin with the `url`.
558
+
* It effectively appends `.*` to the internal regular expression.
559
+
* When the prefix matches, the future state will begin loading.
560
+
* - A `lazyLoad` function.
561
+
* This function should should return a Promise to lazy load the code for one or more [[StateDeclaration]] objects.
562
+
* It should return a [[LazyLoadResult]].
563
+
* Generally, one of the lazy loaded states should have the same name as the future state.
564
+
* The new state will then **replace the future state placeholder** in the registry.
565
+
*
566
+
* ### Additional resources
567
+
*
568
+
* For in depth information on lazy loading and Future States, see the [Lazy Loading Guide](https://ui-router.github.io/guides/lazyload).
569
+
*
570
+
* #### Example: states.js
543
571
* ```js
544
572
*
545
573
* // This child state is a lazy loaded future state
546
574
* // The `lazyLoad` function loads the final state definition
0 commit comments