@angular-wave/angular.ts 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/Makefile +1 -1
  2. package/README.md +3 -3
  3. package/TODO.md +14 -0
  4. package/dist/angular-ts.esm.js +1 -1
  5. package/dist/angular-ts.umd.js +1 -1
  6. package/index.html +2 -1
  7. package/package.json +1 -1
  8. package/src/animations/animate-css-driver.js +2 -2
  9. package/src/animations/animate-css.js +15 -6
  10. package/src/animations/animate-js.js +1 -1
  11. package/src/animations/animate-queue.js +1 -1
  12. package/src/animations/shared.js +0 -14
  13. package/src/core/compile.js +6 -3
  14. package/src/core/q.js +9 -9
  15. package/src/core/sanitize-uri.js +1 -1
  16. package/src/core/sce.js +1 -1
  17. package/src/directive/if.js +0 -79
  18. package/src/directive/if.md +80 -0
  19. package/src/directive/include.js +0 -82
  20. package/src/directive/include.md +86 -0
  21. package/src/directive/repeat.js +0 -1
  22. package/src/loader.js +0 -1
  23. package/src/public.js +0 -2
  24. package/src/router/common/trace.js +1 -1
  25. package/src/router/directives/stateDirectives.js +16 -14
  26. package/src/router/directives/viewDirective.js +2 -2
  27. package/src/router/hooks/resolve.js +3 -4
  28. package/src/router/hooks/views.js +3 -2
  29. package/src/router/state/stateService.js +1 -2
  30. package/src/router/transition/interface.js +14 -14
  31. package/src/router/transition/rejectFactory.js +29 -20
  32. package/src/router/transition/transitionHook.js +5 -5
  33. package/src/router/url/urlMatcher.js +1 -2
  34. package/src/router/url/urlRule.js +1 -1
  35. package/src/router/url/urlRules.js +1 -1
  36. package/src/shared/common.js +0 -1
  37. package/test/module-test.html +44 -12
  38. package/test/router/services.spec.js +71 -0
  39. package/test/router/state-directives.spec.js +1208 -0
  40. package/types/angular.d.ts +132 -124
  41. package/types/index.d.ts +2350 -2187
  42. package/types/jqlite.d.ts +463 -418
  43. package/types/router/core/common/common.d.ts +70 -24
  44. package/types/router/core/common/coreservices.d.ts +30 -32
  45. package/types/router/core/common/glob.d.ts +9 -9
  46. package/types/router/core/common/hof.d.ts +12 -4
  47. package/types/router/core/common/index.d.ts +8 -8
  48. package/types/router/core/common/predicates.d.ts +1 -1
  49. package/types/router/core/common/queue.d.ts +13 -13
  50. package/types/router/core/common/safeConsole.d.ts +3 -3
  51. package/types/router/core/common/strings.d.ts +4 -2
  52. package/types/router/core/common/trace.d.ts +94 -82
  53. package/types/router/core/globals.d.ts +37 -37
  54. package/types/router/core/hooks/coreResolvables.d.ts +5 -3
  55. package/types/router/core/hooks/ignoredTransition.d.ts +4 -2
  56. package/types/router/core/hooks/invalidTransition.d.ts +4 -2
  57. package/types/router/core/hooks/lazyLoad.d.ts +10 -5
  58. package/types/router/core/hooks/onEnterExitRetain.d.ts +10 -4
  59. package/types/router/core/hooks/redirectTo.d.ts +4 -2
  60. package/types/router/core/hooks/resolve.d.ts +10 -4
  61. package/types/router/core/hooks/updateGlobals.d.ts +4 -2
  62. package/types/router/core/hooks/url.d.ts +4 -2
  63. package/types/router/core/hooks/views.d.ts +7 -3
  64. package/types/router/core/index.d.ts +11 -12
  65. package/types/router/core/interface.d.ts +83 -81
  66. package/types/router/core/params/index.d.ts +5 -5
  67. package/types/router/core/params/interface.d.ts +439 -439
  68. package/types/router/core/params/param.d.ts +72 -60
  69. package/types/router/core/params/paramType.d.ts +40 -40
  70. package/types/router/core/params/paramTypes.d.ts +169 -165
  71. package/types/router/core/params/stateParams.d.ts +13 -13
  72. package/types/router/core/path/index.d.ts +2 -2
  73. package/types/router/core/path/pathNode.d.ts +49 -49
  74. package/types/router/core/path/pathUtils.d.ts +100 -74
  75. package/types/router/core/resolve/index.d.ts +3 -3
  76. package/types/router/core/resolve/interface.d.ts +137 -137
  77. package/types/router/core/resolve/resolvable.d.ts +60 -54
  78. package/types/router/core/resolve/resolveContext.d.ts +84 -79
  79. package/types/router/core/router.d.ts +95 -86
  80. package/types/router/core/state/index.d.ts +8 -8
  81. package/types/router/core/state/interface.d.ts +667 -643
  82. package/types/router/core/state/stateBuilder.d.ts +41 -38
  83. package/types/router/core/state/stateMatcher.d.ts +11 -9
  84. package/types/router/core/state/stateObject.d.ts +154 -139
  85. package/types/router/core/state/stateQueueManager.d.ts +26 -21
  86. package/types/router/core/state/stateRegistry.d.ts +124 -121
  87. package/types/router/core/state/stateService.d.ts +380 -343
  88. package/types/router/core/state/targetState.d.ts +74 -69
  89. package/types/router/core/transition/hookBuilder.d.ts +34 -30
  90. package/types/router/core/transition/hookRegistry.d.ts +96 -74
  91. package/types/router/core/transition/index.d.ts +8 -8
  92. package/types/router/core/transition/interface.d.ts +652 -609
  93. package/types/router/core/transition/rejectFactory.d.ts +97 -97
  94. package/types/router/core/transition/transition.d.ts +565 -517
  95. package/types/router/core/transition/transitionEventType.d.ts +20 -11
  96. package/types/router/core/transition/transitionHook.d.ts +90 -82
  97. package/types/router/core/transition/transitionService.d.ts +228 -161
  98. package/types/router/core/url/index.d.ts +8 -8
  99. package/types/router/core/url/interface.d.ts +100 -87
  100. package/types/router/core/url/urlConfig.d.ts +130 -126
  101. package/types/router/core/url/urlMatcher.d.ts +132 -127
  102. package/types/router/core/url/urlMatcherFactory.d.ts +46 -42
  103. package/types/router/core/url/urlRouter.d.ts +91 -75
  104. package/types/router/core/url/urlRule.d.ts +123 -100
  105. package/types/router/core/url/urlRules.d.ts +240 -232
  106. package/types/router/core/url/urlService.d.ts +201 -201
  107. package/types/router/core/view/index.d.ts +2 -2
  108. package/types/router/core/view/interface.d.ts +26 -26
  109. package/types/router/core/view/view.d.ts +152 -143
  110. package/types/router/directives/viewDirective.d.ts +12 -11
  111. package/types/router/index.d.ts +11 -12
  112. package/types/router/interface.d.ts +361 -351
  113. package/types/router/legacy/resolveService.d.ts +44 -40
  114. package/types/router/legacy/stateEvents.d.ts +1 -1
  115. package/types/router/locationServices.d.ts +45 -37
  116. package/types/router/services.d.ts +9 -9
  117. package/types/router/stateFilters.d.ts +3 -3
  118. package/types/router/stateProvider.d.ts +240 -235
  119. package/types/router/statebuilders/onEnterExitRetain.d.ts +4 -2
  120. package/types/router/statebuilders/views.d.ts +35 -22
  121. package/types/router/templateFactory.d.ts +99 -79
  122. package/types/router/viewScroll.d.ts +7 -7
  123. package/src/directive/a.js +0 -37
  124. package/test/directive/a.spec.js +0 -192
  125. package/types/router/angular.d.ts +0 -1
  126. package/types/router/core/vanilla.d.ts +0 -1
  127. package/types/router/directives/stateDirectives.d.ts +0 -3
  128. package/types/router/injectables.d.ts +0 -1
@@ -1,22 +1,32 @@
1
- import { ParamDeclaration, RawParams } from '../params/interface';
2
- import { StateObject } from './stateObject';
3
- import { ViewContext } from '../view/interface';
4
- import { IInjectable } from '../common/common';
5
- import { Transition } from '../transition/transition';
6
- import { TransitionStateHookFn, TransitionOptions } from '../transition/interface';
7
- import { ResolvePolicy, ResolvableLiteral, ProviderLike } from '../resolve/interface';
8
- import { Resolvable } from '../resolve/resolvable';
9
- import { TargetState } from './targetState';
1
+ import { ParamDeclaration, RawParams } from "../params/interface";
2
+ import { StateObject } from "./stateObject";
3
+ import { ViewContext } from "../view/interface";
4
+ import { IInjectable } from "../common/common";
5
+ import { Transition } from "../transition/transition";
6
+ import {
7
+ TransitionStateHookFn,
8
+ TransitionOptions,
9
+ } from "../transition/interface";
10
+ import {
11
+ ResolvePolicy,
12
+ ResolvableLiteral,
13
+ ProviderLike,
14
+ } from "../resolve/interface";
15
+ import { Resolvable } from "../resolve/resolvable";
16
+ import { TargetState } from "./targetState";
10
17
  export declare type StateOrName = string | StateDeclaration | StateObject;
11
18
  export interface TransitionPromise extends Promise<StateObject> {
12
- transition: Transition;
19
+ transition: Transition;
13
20
  }
14
21
  export interface TargetStateDef {
15
- state: StateOrName;
16
- params?: RawParams;
17
- options?: TransitionOptions;
22
+ state: StateOrName;
23
+ params?: RawParams;
24
+ options?: TransitionOptions;
18
25
  }
19
- export declare type ResolveTypes = Resolvable | ResolvableLiteral | ProviderLike;
26
+ export declare type ResolveTypes =
27
+ | Resolvable
28
+ | ResolvableLiteral
29
+ | ProviderLike;
20
30
  /**
21
31
  * Base interface for declaring a view
22
32
  *
@@ -25,38 +35,38 @@ export declare type ResolveTypes = Resolvable | ResolvableLiteral | ProviderLike
25
35
  * Add any additional fields that the framework requires to that interface.
26
36
  */
27
37
  export interface _ViewDeclaration {
28
- /**
29
- * The raw name for the view declaration, i.e., the [[StateDeclaration.views]] property name.
30
- */
31
- $name?: string;
32
- /**
33
- * The normalized address for the `ui-view` which this ViewConfig targets.
34
- *
35
- * A ViewConfig targets a `ui-view` in the DOM (relative to the `uiViewContextAnchor`) which has
36
- * a specific name.
37
- * @example `header` or `$default`
38
- *
39
- * The `uiViewName` can also target a _nested view_ by providing a dot-notation address
40
- * @example `foo.bar` or `foo.$default.bar`
41
- */
42
- $uiViewName?: string;
43
- /**
44
- * The normalized context anchor (state name) for the `uiViewName`
45
- *
46
- * When targeting a `ui-view`, the `uiViewName` address is anchored to a context name (state name).
47
- */
48
- $uiViewContextAnchor?: string;
49
- /**
50
- * A type identifier for the View
51
- *
52
- * This is used when loading prerequisites for the view, before it enters the DOM. Different types of views
53
- * may load differently (e.g., templateProvider+controllerProvider vs component class)
54
- */
55
- $type?: string;
56
- /**
57
- * The context that this view is declared within.
58
- */
59
- $context?: ViewContext;
38
+ /**
39
+ * The raw name for the view declaration, i.e., the [[StateDeclaration.views]] property name.
40
+ */
41
+ $name?: string;
42
+ /**
43
+ * The normalized address for the `ui-view` which this ViewConfig targets.
44
+ *
45
+ * A ViewConfig targets a `ui-view` in the DOM (relative to the `uiViewContextAnchor`) which has
46
+ * a specific name.
47
+ * @example `header` or `$default`
48
+ *
49
+ * The `uiViewName` can also target a _nested view_ by providing a dot-notation address
50
+ * @example `foo.bar` or `foo.$default.bar`
51
+ */
52
+ $uiViewName?: string;
53
+ /**
54
+ * The normalized context anchor (state name) for the `uiViewName`
55
+ *
56
+ * When targeting a `ui-view`, the `uiViewName` address is anchored to a context name (state name).
57
+ */
58
+ $uiViewContextAnchor?: string;
59
+ /**
60
+ * A type identifier for the View
61
+ *
62
+ * This is used when loading prerequisites for the view, before it enters the DOM. Different types of views
63
+ * may load differently (e.g., templateProvider+controllerProvider vs component class)
64
+ */
65
+ $type?: string;
66
+ /**
67
+ * The context that this view is declared within.
68
+ */
69
+ $context?: ViewContext;
60
70
  }
61
71
  /**
62
72
  * The return value of a [[redirectTo]] function
@@ -65,10 +75,14 @@ export interface _ViewDeclaration {
65
75
  * - TargetState: a target state, parameters, and options
66
76
  * - object: an object with a state name and parameters
67
77
  */
68
- export declare type RedirectToResult = string | TargetState | {
69
- state?: string;
70
- params?: RawParams;
71
- } | void;
78
+ export declare type RedirectToResult =
79
+ | string
80
+ | TargetState
81
+ | {
82
+ state?: string;
83
+ params?: RawParams;
84
+ }
85
+ | void;
72
86
  /**
73
87
  * The StateDeclaration object is used to define a state or nested state.
74
88
  *
@@ -93,576 +107,584 @@ export declare type RedirectToResult = string | TargetState | {
93
107
  * ```
94
108
  */
95
109
  export interface StateDeclaration {
96
- /**
97
- * The state name (required)
98
- *
99
- * A unique state name, e.g. `"home"`, `"about"`, `"contacts"`.
100
- * To create a parent/child state use a dot, e.g. `"about.sales"`, `"home.newest"`.
101
- *
102
- * Note: [State] objects require unique names.
103
- * The name is used like an id.
104
- */
105
- name?: string;
106
- /**
107
- * Abstract state indicator
108
- *
109
- * An abstract state can never be directly activated.
110
- * Use an abstract state to provide inherited properties (url, resolve, data, etc) to children states.
111
- */
112
- abstract?: boolean;
113
- /**
114
- * The parent state
115
- *
116
- * Normally, a state's parent is implied from the state's [[name]], e.g., `"parentstate.childstate"`.
117
- *
118
- * Alternatively, you can explicitly set the parent state using this property.
119
- * This allows shorter state names, e.g., `<a ui-sref="childstate">Child</a>`
120
- * instead of `<a ui-sref="parentstate.childstate">Child</a>
121
- *
122
- * When using this property, the state's name should not have any dots in it.
123
- *
124
- * #### Example:
125
- * ```js
126
- * var parentstate = {
127
- * name: 'parentstate'
128
- * }
129
- * var childstate = {
130
- * name: 'childstate',
131
- * parent: 'parentstate'
132
- * // or use a JS var which is the parent StateDeclaration, i.e.:
133
- * // parent: parentstate
134
- * }
135
- * ```
136
- */
137
- parent?: string | StateDeclaration;
138
- /**
139
- * Gets the internal State object API
140
- *
141
- * Gets the *internal API* for a registered state.
142
- *
143
- * Note: the internal [[StateObject]] API is subject to change without notice
144
- * @internal
145
- */
146
- $$state?: () => StateObject;
147
- /**
148
- * Resolve - a mechanism to asynchronously fetch data, participating in the Transition lifecycle
149
- *
150
- * The `resolve:` property defines data (or other dependencies) to be fetched asynchronously when the state is being entered.
151
- * After the data is fetched, it may be used in views, transition hooks or other resolves that belong to this state.
152
- * The data may also be used in any views or resolves that belong to nested states.
153
- *
154
- * ### As an array
155
- *
156
- * Each array element should be a [[ResolvableLiteral]] object.
157
- *
158
- * #### Example:
159
- * The `user` resolve injects the current `Transition` and the `UserService` (using its token, which is a string).
160
- * The [[ResolvableLiteral.resolvePolicy]] sets how the resolve is processed.
161
- * The `user` data, fetched asynchronously, can then be used in a view.
162
- * ```js
163
- * var state = {
164
- * name: 'user',
165
- * url: '/user/:userId
166
- * resolve: [
167
- * {
168
- * token: 'user',
169
- * policy: { when: 'EAGER' },
170
- * deps: ['UserService', Transition],
171
- * resolveFn: (userSvc, trans) => userSvc.fetchUser(trans.params().userId) },
172
- * }
173
- * ]
174
- * }
175
- * ```
176
- *
177
- * Note: an Angular 2 style [`useFactory` provider literal](https://angular.io/docs/ts/latest/cookbook/dependency-injection.html#!#provide)
178
- * may also be used. See [[ProviderLike]].
179
- * #### Example:
180
- * ```
181
- * resolve: [
182
- * { provide: 'token', useFactory: (http) => http.get('/'), deps: [ Http ] },
183
- * ]
184
- * ```
185
- *
186
- * ### As an object
187
- *
188
- * The `resolve` property may be an object where:
189
- * - Each key (string) is the name of the dependency.
190
- * - Each value (function) is an injectable function which returns the dependency, or a promise for the dependency.
191
- *
192
- * This style is based on AngularJS injectable functions, but can be used with any UI-Router implementation.
193
- * If your code will be minified, the function should be ["annotated" in the AngularJS manner](https://docs.angularjs.org/guide/di#dependency-annotation).
194
- *
195
- * #### AngularJS Example:
196
- * ```js
197
- * resolve: {
198
- * // If you inject `myStateDependency` into a controller, you'll get "abc"
199
- * myStateDependency: function() {
200
- * return "abc";
201
- * },
202
- * // Dependencies are annotated in "Inline Array Annotation"
203
- * myAsyncData: ['$http', '$transition$' function($http, $transition$) {
204
- * // Return a promise (async) for the data
205
- * return $http.get("/foos/" + $transition$.params().foo);
206
- * }]
207
- * }
208
- * ```
209
- *
210
- * Note: You cannot specify a policy for each Resolvable, nor can you use non-string
211
- * tokens when using the object style `resolve:` block.
212
- *
213
- * ### Lifecycle
214
- *
215
- * Since a resolve function can return a promise, the router will delay entering the state until the promises are ready.
216
- * If any of the promises are rejected, the Transition is aborted with an Error.
217
- *
218
- * By default, resolves for a state are fetched just before that state is entered.
219
- * Note that only states which are being *entered* during the `Transition` have their resolves fetched.
220
- * States that are "retained" do not have their resolves re-fetched.
221
- *
222
- * If you are currently in a parent state `parent` and are transitioning to a child state `parent.child`, the
223
- * previously resolved data for state `parent` can be injected into `parent.child` without delay.
224
- *
225
- * Any resolved data for `parent.child` is retained until `parent.child` is exited, e.g., by transitioning back to the `parent` state.
226
- *
227
- * Because of this scoping and lifecycle, resolves are a great place to fetch your application's primary data.
228
- *
229
- * ### Injecting resolves into other things
230
- *
231
- * During a transition, Resolve data can be injected into:
232
- *
233
- * - Views (the components which fill a `ui-view` tag)
234
- * - Transition Hooks
235
- * - Other resolves (a resolve may depend on asynchronous data from a different resolve)
236
- *
237
- * ### Injecting other things into resolves
238
- *
239
- * Resolve functions usually have dependencies on some other API(s).
240
- * The dependencies are usually declared and injected into the resolve function.
241
- * A common pattern is to inject a custom service such as `UserService`.
242
- * The resolve then delegates to a service method, such as `UserService.list()`;
243
- *
244
- * #### Special injectable tokens
245
- *
246
- * - `UIRouter`: The [[UIRouter]] instance which has references to all the UI-Router services.
247
- * - `Transition`: The current [[Transition]] object; information and API about the current transition, such as
248
- * "to" and "from" State Parameters and transition options.
249
- * - `'$transition$'`: A string alias for the `Transition` injectable
250
- * - `'$state$'`: For `onEnter`/`onExit`/`onRetain`, the state being entered/exited/retained.
251
- * - Other resolve tokens: A resolve can depend on another resolve, either from the same state, or from any parent state.
252
- *
253
- * #### Example:
254
- * ```js
255
- * // Injecting a resolve into another resolve
256
- * resolve: [
257
- * // Define a resolve 'allusers' which delegates to the UserService.list()
258
- * // which returns a promise (async) for all the users
259
- * { provide: 'allusers', useFactory: (UserService) => UserService.list(), deps: [UserService] },
260
- *
261
- * // Define a resolve 'user' which depends on the allusers resolve.
262
- * // This resolve function is not called until 'allusers' is ready.
263
- * { provide: 'user', (allusers, trans) => _.find(allusers, trans.params().userId, deps: ['allusers', Transition] }
264
- * }
265
- * ```
266
- */
267
- resolve?: ResolveTypes[] | {
110
+ /**
111
+ * The state name (required)
112
+ *
113
+ * A unique state name, e.g. `"home"`, `"about"`, `"contacts"`.
114
+ * To create a parent/child state use a dot, e.g. `"about.sales"`, `"home.newest"`.
115
+ *
116
+ * Note: [State] objects require unique names.
117
+ * The name is used like an id.
118
+ */
119
+ name?: string;
120
+ /**
121
+ * Abstract state indicator
122
+ *
123
+ * An abstract state can never be directly activated.
124
+ * Use an abstract state to provide inherited properties (url, resolve, data, etc) to children states.
125
+ */
126
+ abstract?: boolean;
127
+ /**
128
+ * The parent state
129
+ *
130
+ * Normally, a state's parent is implied from the state's [[name]], e.g., `"parentstate.childstate"`.
131
+ *
132
+ * Alternatively, you can explicitly set the parent state using this property.
133
+ * This allows shorter state names, e.g., `<a ui-sref="childstate">Child</a>`
134
+ * instead of `<a ui-sref="parentstate.childstate">Child</a>
135
+ *
136
+ * When using this property, the state's name should not have any dots in it.
137
+ *
138
+ * #### Example:
139
+ * ```js
140
+ * var parentstate = {
141
+ * name: 'parentstate'
142
+ * }
143
+ * var childstate = {
144
+ * name: 'childstate',
145
+ * parent: 'parentstate'
146
+ * // or use a JS var which is the parent StateDeclaration, i.e.:
147
+ * // parent: parentstate
148
+ * }
149
+ * ```
150
+ */
151
+ parent?: string | StateDeclaration;
152
+ /**
153
+ * Gets the internal State object API
154
+ *
155
+ * Gets the *internal API* for a registered state.
156
+ *
157
+ * Note: the internal [[StateObject]] API is subject to change without notice
158
+ * @internal
159
+ */
160
+ $$state?: () => StateObject;
161
+ /**
162
+ * Resolve - a mechanism to asynchronously fetch data, participating in the Transition lifecycle
163
+ *
164
+ * The `resolve:` property defines data (or other dependencies) to be fetched asynchronously when the state is being entered.
165
+ * After the data is fetched, it may be used in views, transition hooks or other resolves that belong to this state.
166
+ * The data may also be used in any views or resolves that belong to nested states.
167
+ *
168
+ * ### As an array
169
+ *
170
+ * Each array element should be a [[ResolvableLiteral]] object.
171
+ *
172
+ * #### Example:
173
+ * The `user` resolve injects the current `Transition` and the `UserService` (using its token, which is a string).
174
+ * The [[ResolvableLiteral.resolvePolicy]] sets how the resolve is processed.
175
+ * The `user` data, fetched asynchronously, can then be used in a view.
176
+ * ```js
177
+ * var state = {
178
+ * name: 'user',
179
+ * url: '/user/:userId
180
+ * resolve: [
181
+ * {
182
+ * token: 'user',
183
+ * policy: { when: 'EAGER' },
184
+ * deps: ['UserService', Transition],
185
+ * resolveFn: (userSvc, trans) => userSvc.fetchUser(trans.params().userId) },
186
+ * }
187
+ * ]
188
+ * }
189
+ * ```
190
+ *
191
+ * Note: an Angular 2 style [`useFactory` provider literal](https://angular.io/docs/ts/latest/cookbook/dependency-injection.html#!#provide)
192
+ * may also be used. See [[ProviderLike]].
193
+ * #### Example:
194
+ * ```
195
+ * resolve: [
196
+ * { provide: 'token', useFactory: (http) => http.get('/'), deps: [ Http ] },
197
+ * ]
198
+ * ```
199
+ *
200
+ * ### As an object
201
+ *
202
+ * The `resolve` property may be an object where:
203
+ * - Each key (string) is the name of the dependency.
204
+ * - Each value (function) is an injectable function which returns the dependency, or a promise for the dependency.
205
+ *
206
+ * This style is based on AngularJS injectable functions, but can be used with any UI-Router implementation.
207
+ * If your code will be minified, the function should be ["annotated" in the AngularJS manner](https://docs.angularjs.org/guide/di#dependency-annotation).
208
+ *
209
+ * #### AngularJS Example:
210
+ * ```js
211
+ * resolve: {
212
+ * // If you inject `myStateDependency` into a controller, you'll get "abc"
213
+ * myStateDependency: function() {
214
+ * return "abc";
215
+ * },
216
+ * // Dependencies are annotated in "Inline Array Annotation"
217
+ * myAsyncData: ['$http', '$transition$' function($http, $transition$) {
218
+ * // Return a promise (async) for the data
219
+ * return $http.get("/foos/" + $transition$.params().foo);
220
+ * }]
221
+ * }
222
+ * ```
223
+ *
224
+ * Note: You cannot specify a policy for each Resolvable, nor can you use non-string
225
+ * tokens when using the object style `resolve:` block.
226
+ *
227
+ * ### Lifecycle
228
+ *
229
+ * Since a resolve function can return a promise, the router will delay entering the state until the promises are ready.
230
+ * If any of the promises are rejected, the Transition is aborted with an Error.
231
+ *
232
+ * By default, resolves for a state are fetched just before that state is entered.
233
+ * Note that only states which are being *entered* during the `Transition` have their resolves fetched.
234
+ * States that are "retained" do not have their resolves re-fetched.
235
+ *
236
+ * If you are currently in a parent state `parent` and are transitioning to a child state `parent.child`, the
237
+ * previously resolved data for state `parent` can be injected into `parent.child` without delay.
238
+ *
239
+ * Any resolved data for `parent.child` is retained until `parent.child` is exited, e.g., by transitioning back to the `parent` state.
240
+ *
241
+ * Because of this scoping and lifecycle, resolves are a great place to fetch your application's primary data.
242
+ *
243
+ * ### Injecting resolves into other things
244
+ *
245
+ * During a transition, Resolve data can be injected into:
246
+ *
247
+ * - Views (the components which fill a `ui-view` tag)
248
+ * - Transition Hooks
249
+ * - Other resolves (a resolve may depend on asynchronous data from a different resolve)
250
+ *
251
+ * ### Injecting other things into resolves
252
+ *
253
+ * Resolve functions usually have dependencies on some other API(s).
254
+ * The dependencies are usually declared and injected into the resolve function.
255
+ * A common pattern is to inject a custom service such as `UserService`.
256
+ * The resolve then delegates to a service method, such as `UserService.list()`;
257
+ *
258
+ * #### Special injectable tokens
259
+ *
260
+ * - `UIRouter`: The [[UIRouter]] instance which has references to all the UI-Router services.
261
+ * - `Transition`: The current [[Transition]] object; information and API about the current transition, such as
262
+ * "to" and "from" State Parameters and transition options.
263
+ * - `'$transition$'`: A string alias for the `Transition` injectable
264
+ * - `'$state$'`: For `onEnter`/`onExit`/`onRetain`, the state being entered/exited/retained.
265
+ * - Other resolve tokens: A resolve can depend on another resolve, either from the same state, or from any parent state.
266
+ *
267
+ * #### Example:
268
+ * ```js
269
+ * // Injecting a resolve into another resolve
270
+ * resolve: [
271
+ * // Define a resolve 'allusers' which delegates to the UserService.list()
272
+ * // which returns a promise (async) for all the users
273
+ * { provide: 'allusers', useFactory: (UserService) => UserService.list(), deps: [UserService] },
274
+ *
275
+ * // Define a resolve 'user' which depends on the allusers resolve.
276
+ * // This resolve function is not called until 'allusers' is ready.
277
+ * { provide: 'user', (allusers, trans) => _.find(allusers, trans.params().userId, deps: ['allusers', Transition] }
278
+ * }
279
+ * ```
280
+ */
281
+ resolve?:
282
+ | ResolveTypes[]
283
+ | {
268
284
  [key: string]: IInjectable;
269
- };
270
- /**
271
- * Sets the resolve policy defaults for all resolves on this state
272
- *
273
- * This should be an [[ResolvePolicy]] object.
274
- *
275
- * It can contain the following optional keys/values:
276
- *
277
- * - `when`: (optional) defines when the resolve is fetched. Accepted values: "LAZY" or "EAGER"
278
- * - `async`: (optional) if the transition waits for the resolve. Accepted values: "WAIT", "NOWAIT", {@link CustomAsyncPolicy}
279
- *
280
- * See [[ResolvePolicy]] for more details.
281
- */
282
- resolvePolicy?: ResolvePolicy;
283
- /**
284
- * The url fragment for the state
285
- *
286
- * A URL fragment (with optional parameters) which is used to match the browser location with this state.
287
- *
288
- * This fragment will be appended to the parent state's URL in order to build up the overall URL for this state.
289
- * See [[UrlMatcher]] for details on acceptable patterns.
290
- *
291
- * @examples
292
- * ```js
293
- *
294
- * url: "/home"
295
- * // Define a parameter named 'userid'
296
- * url: "/users/:userid"
297
- * // param 'bookid' has a custom regexp
298
- * url: "/books/{bookid:[a-zA-Z_-]}"
299
- * // param 'categoryid' is of type 'int'
300
- * url: "/books/{categoryid:int}"
301
- * // two parameters for this state
302
- * url: "/books/{publishername:string}/{categoryid:int}"
303
- * // Query parameters
304
- * url: "/messages?before&after"
305
- * // Query parameters of type 'date'
306
- * url: "/messages?{before:date}&{after:date}"
307
- * // Path and query parameters
308
- * url: "/messages/:mailboxid?{before:date}&{after:date}"
309
- * ```
310
- */
311
- url?: string;
312
- /**
313
- * Params configuration
314
- *
315
- * An object which optionally configures parameters declared in the url, or defines additional non-url
316
- * parameters. For each parameter being configured, add a [[ParamDeclaration]] keyed to the name of the parameter.
317
- *
318
- * #### Example:
319
- * ```js
320
- * params: {
321
- * param1: {
322
- * type: "int",
323
- * array: true,
324
- * value: []
325
- * },
326
- * param2: {
327
- * value: "index"
328
- * }
329
- * }
330
- * ```
331
- */
332
- params?: {
333
- [key: string]: ParamDeclaration | any;
334
- };
335
- /**
336
- * Named views
337
- *
338
- * An optional object which defines multiple views, or explicitly targets specific named ui-views.
339
- *
340
- * - What is a view config
341
- * - What is a ui-view
342
- * - Shorthand controller/template
343
- * - Incompatible with ^
344
- *
345
- * Examples:
346
- *
347
- * Targets three named ui-views in the parent state's template
348
- *
349
- * #### Example:
350
- * ```js
351
- * views: {
352
- * header: {
353
- * controller: "headerCtrl",
354
- * templateUrl: "header.html"
355
- * }, body: {
356
- * controller: "bodyCtrl",
357
- * templateUrl: "body.html"
358
- * }, footer: {
359
- * controller: "footCtrl",
360
- * templateUrl: "footer.html"
361
- * }
362
- * }
363
- * ```
364
- *
365
- * @example
366
- * ```js
367
- * // Targets named ui-view="header" from ancestor state 'top''s template, and
368
- * // named `ui-view="body" from parent state's template.
369
- * views: {
370
- * 'header@top': {
371
- * controller: "msgHeaderCtrl",
372
- * templateUrl: "msgHeader.html"
373
- * }, 'body': {
374
- * controller: "messagesCtrl",
375
- * templateUrl: "messages.html"
376
- * }
377
- * }
378
- * ```
379
- */
380
- views?: {
381
- [key: string]: _ViewDeclaration;
382
- };
383
- /**
384
- * An inherited property to store state data
385
- *
386
- * This is a spot for you to store inherited state metadata.
387
- * Child states' `data` object will prototypally inherit from their parent state.
388
- *
389
- * This is a good spot to put metadata such as `requiresAuth`.
390
- *
391
- * Note: because prototypal inheritance is used, changes to parent `data` objects reflect in the child `data` objects.
392
- * Care should be taken if you are using `hasOwnProperty` on the `data` object.
393
- * Properties from parent objects will return false for `hasOwnProperty`.
394
- */
395
- data?: any;
396
- /**
397
- * Synchronously or asynchronously redirects Transitions to a different state/params
398
- *
399
- * If this property is defined, a Transition directly to this state will be redirected based on the property's value.
400
- *
401
- * - If the value is a `string`, the Transition is redirected to the state named by the string.
402
- *
403
- * - If the property is an object with a `state` and/or `params` property,
404
- * the Transition is redirected to the named `state` and/or `params`.
405
- *
406
- * - If the value is a [[TargetState]] the Transition is redirected to the `TargetState`
407
- *
408
- * - If the property is a function:
409
- * - The function is called with the current [[Transition]]
410
- * - The return value is processed using the previously mentioned rules.
411
- * - If the return value is a promise, the promise is waited for, then the resolved async value is processed using the same rules.
412
- *
413
- * Note: `redirectTo` is processed as an `onStart` hook, before `LAZY` resolves.
414
- * If your redirect function relies on resolve data, get the [[Transition.injector]] and get a
415
- * promise for the resolve data using [[UIInjector.getAsync]].
416
- *
417
- * #### Example:
418
- * ```js
419
- * // a string
420
- * .state('A', {
421
- * redirectTo: 'A.B'
422
- * })
423
- *
424
- * // a {state, params} object
425
- * .state('C', {
426
- * redirectTo: { state: 'C.D', params: { foo: 'index' } }
427
- * })
428
- *
429
- * // a fn
430
- * .state('E', {
431
- * redirectTo: () => "A"
432
- * })
433
- *
434
- * // a fn conditionally returning a {state, params}
435
- * .state('F', {
436
- * redirectTo: (trans) => {
437
- * if (trans.params().foo < 10)
438
- * return { state: 'F', params: { foo: 10 } };
439
- * }
440
- * })
441
- *
442
- * // a fn returning a promise for a redirect
443
- * .state('G', {
444
- * redirectTo: (trans) => {
445
- * let svc = trans.injector().get('SomeAsyncService')
446
- * let promise = svc.getAsyncRedirectTo(trans.params.foo);
447
- * return promise;
448
- * }
449
- * })
450
- *
451
- * // a fn that fetches resolve data
452
- * .state('G', {
453
- * redirectTo: (trans) => {
454
- * // getAsync tells the resolve to load
455
- * let resolvePromise = trans.injector().getAsync('SomeResolve')
456
- * return resolvePromise.then(resolveData => resolveData === 'login' ? 'login' : null);
457
- * }
458
- * })
459
- * ```
460
- */
461
- redirectTo?: RedirectToResult | ((transition: Transition) => RedirectToResult) | ((transition: Transition) => Promise<RedirectToResult>);
462
- /**
463
- * A Transition Hook called with the state is being entered. See: [[IHookRegistry.onEnter]]
464
- *
465
- * #### Example:
466
- * ```js
467
- * .state({
468
- * name: 'mystate',
469
- * onEnter: function(trans, state) {
470
- * console.log("Entering " + state.name);
471
- * }
472
- * });
473
- * ```
474
- *
475
- * Note: The above `onEnter` on the state declaration is effectively sugar for:
476
- *
477
- * ```js
478
- * transitionService.onEnter({ entering: 'mystate' }, function(trans, state) {
479
- * console.log("Entering " + state.name);
480
- * });
481
- * ```
482
- */
483
- onEnter?: TransitionStateHookFn;
484
- /**
485
- * A [[TransitionStateHookFn]] called with the state is being retained/kept. See: [[IHookRegistry.onRetain]]
486
- *
487
- * #### Example:
488
- * ```js
489
- * .state({
490
- * name: 'mystate',
491
- * onRetain: function(trans, state) {
492
- * console.log(state.name + " is still active!");
493
- * }
494
- * });
495
- * ```
496
- *
497
- * Note: The above `onRetain` on the state declaration is effectively sugar for:
498
- *
499
- * ```js
500
- * transitionService.onRetain({ retained: 'mystate' }, function(trans, state) {
501
- * console.log(state.name + " is still active!");
502
- * });
503
- * ```
504
- */
505
- onRetain?: TransitionStateHookFn;
506
- /**
507
- * A Transition Hook called with the state is being exited. See: [[IHookRegistry.onExit]]
508
- *
509
- * #### Example:
510
- * ```js
511
- * .state({
512
- * name: 'mystate',
513
- * onExit: function(trans, state) {
514
- * console.log("Leaving " + state.name);
515
- * }
516
- * });
517
- * ```
518
- *
519
- * Note: The above `onRetain` on the state declaration is effectively sugar for:
520
- *
521
- * ```js
522
- * transitionService.onExit({ exiting: 'mystate' }, function(trans, state) {
523
- * console.log("Leaving " + state.name);
524
- * });
525
- * ```
526
- */
527
- onExit?: TransitionStateHookFn;
528
- /**
529
- * A function used to lazy load code
530
- *
531
- * The `lazyLoad` function is invoked before the state is activated.
532
- * The transition waits while the code is loading.
533
- *
534
- * The function should load the code that is required to activate the state.
535
- * For example, it may load a component class, or some service code.
536
- * The function must return a promise which resolves when loading is complete.
537
- *
538
- * For example, this code lazy loads a service before the `abc` state is activated:
539
- *
540
- * ```
541
- * .state('abc', {
542
- * lazyLoad: (transition, state) => import('./abcService')
543
- * }
544
- * ```
545
- *
546
- * The `abcService` file is imported and loaded
547
- * (it is assumed that the `abcService` file knows how to register itself as a service).
548
- *
549
- * #### Lifecycle
550
- *
551
- * - The `lazyLoad` function is invoked if a transition is going to enter the state.
552
- * - The function is invoked before the transition starts (using an `onBefore` transition hook).
553
- * - The function is only invoked once; while the `lazyLoad` function is loading code, it will not be invoked again.
554
- * For example, if the user double clicks a ui-sref, `lazyLoad` is only invoked once even though there were two transition attempts.
555
- * Instead, the existing lazy load promise is re-used.
556
- * - When the promise resolves successfully, the `lazyLoad` property is deleted from the state declaration.
557
- * - If the promise resolves to a [[LazyLoadResult]] which has an array of `states`, those states are registered.
558
- * - The original transition is retried (this time without the `lazyLoad` property present).
559
- *
560
- * - If the `lazyLoad` function fails, then the transition also fails.
561
- * The failed transition (and the `lazyLoad` function) could potentially be retried by the user.
562
- *
563
- * ### Lazy loading state definitions (Future States)
564
- *
565
- * State definitions can also be lazy loaded.
566
- * This might be desirable when building large, multi-module applications.
567
- *
568
- * To lazy load state definitions, a Future State should be registered as a placeholder.
569
- * When the state definitions are lazy loaded, the Future State is deregistered.
570
- *
571
- * A future state can act as a placeholder for a single state, or for an entire module of states and substates.
572
- * A future state should have:
573
- *
574
- * - A `name` which ends in `.**`.
575
- * A future state's `name` property acts as a wildcard [[Glob]].
576
- * It matches any state name that starts with the `name` (including child states that are not yet loaded).
577
- * - A `url` prefix.
578
- * A future state's `url` property acts as a wildcard.
579
- * UI-Router matches all paths that begin with the `url`.
580
- * It effectively appends `.*` to the internal regular expression.
581
- * When the prefix matches, the future state will begin loading.
582
- * - A `lazyLoad` function.
583
- * This function should should return a Promise to lazy load the code for one or more [[StateDeclaration]] objects.
584
- * It should return a [[LazyLoadResult]].
585
- * Generally, one of the lazy loaded states should have the same name as the future state.
586
- * The new state will then **replace the future state placeholder** in the registry.
587
- *
588
- * ### Additional resources
589
- *
590
- * For in depth information on lazy loading and Future States, see the [Lazy Loading Guide](https://ui-router.github.io/guides/lazyload).
591
- *
592
- * #### Example: states.js
593
- * ```js
594
- *
595
- * // This child state is a lazy loaded future state
596
- * // The `lazyLoad` function loads the final state definition
597
- * {
598
- * name: 'parent.**',
599
- * url: '/parent',
600
- * lazyLoad: () => import('./lazy.states.js')
601
- * }
602
- * ```
603
- *
604
- * #### Example: lazy.states.js
605
- *
606
- * This file is lazy loaded. It exports an array of states.
607
- *
608
- * ```js
609
- * import {ChildComponent} from "./child.component.js";
610
- * import {ParentComponent} from "./parent.component.js";
611
- *
612
- * // This fully defined state replaces the future state
613
- * let parentState = {
614
- * // the name should match the future state
615
- * name: 'parent',
616
- * url: '/parent/:parentId',
617
- * component: ParentComponent,
618
- * resolve: {
619
- * parentData: ($transition$, ParentService) =>
620
- * ParentService.get($transition$.params().parentId)
621
- * }
622
- * }
623
- *
624
- * let childState = {
625
- * name: 'parent.child',
626
- * url: '/child/:childId',
627
- * params: {
628
- * childId: "default"
629
- * },
630
- * resolve: {
631
- * childData: ($transition$, ChildService) =>
632
- * ChildService.get($transition$.params().childId)
633
- * }
634
- * };
635
- *
636
- * // This array of states will be registered by the lazyLoad hook
637
- * let lazyLoadResults = {
638
- * states: [ parentState, childState ]
639
- * };
640
- *
641
- * export default lazyLoadResults;
642
- * ```
643
- *
644
- * @param transition the [[Transition]] that is activating the future state
645
- * @param state the [[StateDeclaration]] that the `lazyLoad` function is declared on
646
- * @return a Promise to load the states.
647
- * Optionally, if the promise resolves to a [[LazyLoadResult]],
648
- * the states will be registered with the [[StateRegistry]].
649
- */
650
- lazyLoad?: (transition: Transition, state: StateDeclaration) => Promise<LazyLoadResult>;
651
- /**
652
- * Marks all the state's parameters as `dynamic`.
653
- *
654
- * All parameters on the state will use this value for `dynamic` as a default.
655
- * Individual parameters may override this default using [[ParamDeclaration.dynamic]] in the [[params]] block.
656
- *
657
- * Note: this value overrides the `dynamic` value on a custom parameter type ([[ParamTypeDefinition.dynamic]]).
658
- */
659
- dynamic?: boolean;
660
- /**
661
- * Marks all query parameters as [[ParamDeclaration.dynamic]]
662
- *
663
- * @deprecated use either [[dynamic]] or [[ParamDeclaration.dynamic]]
664
- */
665
- reloadOnSearch?: boolean;
285
+ };
286
+ /**
287
+ * Sets the resolve policy defaults for all resolves on this state
288
+ *
289
+ * This should be an [[ResolvePolicy]] object.
290
+ *
291
+ * It can contain the following optional keys/values:
292
+ *
293
+ * - `when`: (optional) defines when the resolve is fetched. Accepted values: "LAZY" or "EAGER"
294
+ * - `async`: (optional) if the transition waits for the resolve. Accepted values: "WAIT", "NOWAIT", {@link CustomAsyncPolicy}
295
+ *
296
+ * See [[ResolvePolicy]] for more details.
297
+ */
298
+ resolvePolicy?: ResolvePolicy;
299
+ /**
300
+ * The url fragment for the state
301
+ *
302
+ * A URL fragment (with optional parameters) which is used to match the browser location with this state.
303
+ *
304
+ * This fragment will be appended to the parent state's URL in order to build up the overall URL for this state.
305
+ * See [[UrlMatcher]] for details on acceptable patterns.
306
+ *
307
+ * @examples
308
+ * ```js
309
+ *
310
+ * url: "/home"
311
+ * // Define a parameter named 'userid'
312
+ * url: "/users/:userid"
313
+ * // param 'bookid' has a custom regexp
314
+ * url: "/books/{bookid:[a-zA-Z_-]}"
315
+ * // param 'categoryid' is of type 'int'
316
+ * url: "/books/{categoryid:int}"
317
+ * // two parameters for this state
318
+ * url: "/books/{publishername:string}/{categoryid:int}"
319
+ * // Query parameters
320
+ * url: "/messages?before&after"
321
+ * // Query parameters of type 'date'
322
+ * url: "/messages?{before:date}&{after:date}"
323
+ * // Path and query parameters
324
+ * url: "/messages/:mailboxid?{before:date}&{after:date}"
325
+ * ```
326
+ */
327
+ url?: string;
328
+ /**
329
+ * Params configuration
330
+ *
331
+ * An object which optionally configures parameters declared in the url, or defines additional non-url
332
+ * parameters. For each parameter being configured, add a [[ParamDeclaration]] keyed to the name of the parameter.
333
+ *
334
+ * #### Example:
335
+ * ```js
336
+ * params: {
337
+ * param1: {
338
+ * type: "int",
339
+ * array: true,
340
+ * value: []
341
+ * },
342
+ * param2: {
343
+ * value: "index"
344
+ * }
345
+ * }
346
+ * ```
347
+ */
348
+ params?: {
349
+ [key: string]: ParamDeclaration | any;
350
+ };
351
+ /**
352
+ * Named views
353
+ *
354
+ * An optional object which defines multiple views, or explicitly targets specific named ui-views.
355
+ *
356
+ * - What is a view config
357
+ * - What is a ui-view
358
+ * - Shorthand controller/template
359
+ * - Incompatible with ^
360
+ *
361
+ * Examples:
362
+ *
363
+ * Targets three named ui-views in the parent state's template
364
+ *
365
+ * #### Example:
366
+ * ```js
367
+ * views: {
368
+ * header: {
369
+ * controller: "headerCtrl",
370
+ * templateUrl: "header.html"
371
+ * }, body: {
372
+ * controller: "bodyCtrl",
373
+ * templateUrl: "body.html"
374
+ * }, footer: {
375
+ * controller: "footCtrl",
376
+ * templateUrl: "footer.html"
377
+ * }
378
+ * }
379
+ * ```
380
+ *
381
+ * @example
382
+ * ```js
383
+ * // Targets named ui-view="header" from ancestor state 'top''s template, and
384
+ * // named `ui-view="body" from parent state's template.
385
+ * views: {
386
+ * 'header@top': {
387
+ * controller: "msgHeaderCtrl",
388
+ * templateUrl: "msgHeader.html"
389
+ * }, 'body': {
390
+ * controller: "messagesCtrl",
391
+ * templateUrl: "messages.html"
392
+ * }
393
+ * }
394
+ * ```
395
+ */
396
+ views?: {
397
+ [key: string]: _ViewDeclaration;
398
+ };
399
+ /**
400
+ * An inherited property to store state data
401
+ *
402
+ * This is a spot for you to store inherited state metadata.
403
+ * Child states' `data` object will prototypally inherit from their parent state.
404
+ *
405
+ * This is a good spot to put metadata such as `requiresAuth`.
406
+ *
407
+ * Note: because prototypal inheritance is used, changes to parent `data` objects reflect in the child `data` objects.
408
+ * Care should be taken if you are using `hasOwnProperty` on the `data` object.
409
+ * Properties from parent objects will return false for `hasOwnProperty`.
410
+ */
411
+ data?: any;
412
+ /**
413
+ * Synchronously or asynchronously redirects Transitions to a different state/params
414
+ *
415
+ * If this property is defined, a Transition directly to this state will be redirected based on the property's value.
416
+ *
417
+ * - If the value is a `string`, the Transition is redirected to the state named by the string.
418
+ *
419
+ * - If the property is an object with a `state` and/or `params` property,
420
+ * the Transition is redirected to the named `state` and/or `params`.
421
+ *
422
+ * - If the value is a [[TargetState]] the Transition is redirected to the `TargetState`
423
+ *
424
+ * - If the property is a function:
425
+ * - The function is called with the current [[Transition]]
426
+ * - The return value is processed using the previously mentioned rules.
427
+ * - If the return value is a promise, the promise is waited for, then the resolved async value is processed using the same rules.
428
+ *
429
+ * Note: `redirectTo` is processed as an `onStart` hook, before `LAZY` resolves.
430
+ * If your redirect function relies on resolve data, get the [[Transition.injector]] and get a
431
+ * promise for the resolve data using [[UIInjector.getAsync]].
432
+ *
433
+ * #### Example:
434
+ * ```js
435
+ * // a string
436
+ * .state('A', {
437
+ * redirectTo: 'A.B'
438
+ * })
439
+ *
440
+ * // a {state, params} object
441
+ * .state('C', {
442
+ * redirectTo: { state: 'C.D', params: { foo: 'index' } }
443
+ * })
444
+ *
445
+ * // a fn
446
+ * .state('E', {
447
+ * redirectTo: () => "A"
448
+ * })
449
+ *
450
+ * // a fn conditionally returning a {state, params}
451
+ * .state('F', {
452
+ * redirectTo: (trans) => {
453
+ * if (trans.params().foo < 10)
454
+ * return { state: 'F', params: { foo: 10 } };
455
+ * }
456
+ * })
457
+ *
458
+ * // a fn returning a promise for a redirect
459
+ * .state('G', {
460
+ * redirectTo: (trans) => {
461
+ * let svc = trans.injector().get('SomeAsyncService')
462
+ * let promise = svc.getAsyncRedirectTo(trans.params.foo);
463
+ * return promise;
464
+ * }
465
+ * })
466
+ *
467
+ * // a fn that fetches resolve data
468
+ * .state('G', {
469
+ * redirectTo: (trans) => {
470
+ * // getAsync tells the resolve to load
471
+ * let resolvePromise = trans.injector().getAsync('SomeResolve')
472
+ * return resolvePromise.then(resolveData => resolveData === 'login' ? 'login' : null);
473
+ * }
474
+ * })
475
+ * ```
476
+ */
477
+ redirectTo?:
478
+ | RedirectToResult
479
+ | ((transition: Transition) => RedirectToResult)
480
+ | ((transition: Transition) => Promise<RedirectToResult>);
481
+ /**
482
+ * A Transition Hook called with the state is being entered. See: [[IHookRegistry.onEnter]]
483
+ *
484
+ * #### Example:
485
+ * ```js
486
+ * .state({
487
+ * name: 'mystate',
488
+ * onEnter: function(trans, state) {
489
+ * console.log("Entering " + state.name);
490
+ * }
491
+ * });
492
+ * ```
493
+ *
494
+ * Note: The above `onEnter` on the state declaration is effectively sugar for:
495
+ *
496
+ * ```js
497
+ * transitionService.onEnter({ entering: 'mystate' }, function(trans, state) {
498
+ * console.log("Entering " + state.name);
499
+ * });
500
+ * ```
501
+ */
502
+ onEnter?: TransitionStateHookFn;
503
+ /**
504
+ * A [[TransitionStateHookFn]] called with the state is being retained/kept. See: [[IHookRegistry.onRetain]]
505
+ *
506
+ * #### Example:
507
+ * ```js
508
+ * .state({
509
+ * name: 'mystate',
510
+ * onRetain: function(trans, state) {
511
+ * console.log(state.name + " is still active!");
512
+ * }
513
+ * });
514
+ * ```
515
+ *
516
+ * Note: The above `onRetain` on the state declaration is effectively sugar for:
517
+ *
518
+ * ```js
519
+ * transitionService.onRetain({ retained: 'mystate' }, function(trans, state) {
520
+ * console.log(state.name + " is still active!");
521
+ * });
522
+ * ```
523
+ */
524
+ onRetain?: TransitionStateHookFn;
525
+ /**
526
+ * A Transition Hook called with the state is being exited. See: [[IHookRegistry.onExit]]
527
+ *
528
+ * #### Example:
529
+ * ```js
530
+ * .state({
531
+ * name: 'mystate',
532
+ * onExit: function(trans, state) {
533
+ * console.log("Leaving " + state.name);
534
+ * }
535
+ * });
536
+ * ```
537
+ *
538
+ * Note: The above `onRetain` on the state declaration is effectively sugar for:
539
+ *
540
+ * ```js
541
+ * transitionService.onExit({ exiting: 'mystate' }, function(trans, state) {
542
+ * console.log("Leaving " + state.name);
543
+ * });
544
+ * ```
545
+ */
546
+ onExit?: TransitionStateHookFn;
547
+ /**
548
+ * A function used to lazy load code
549
+ *
550
+ * The `lazyLoad` function is invoked before the state is activated.
551
+ * The transition waits while the code is loading.
552
+ *
553
+ * The function should load the code that is required to activate the state.
554
+ * For example, it may load a component class, or some service code.
555
+ * The function must return a promise which resolves when loading is complete.
556
+ *
557
+ * For example, this code lazy loads a service before the `abc` state is activated:
558
+ *
559
+ * ```
560
+ * .state('abc', {
561
+ * lazyLoad: (transition, state) => import('./abcService')
562
+ * }
563
+ * ```
564
+ *
565
+ * The `abcService` file is imported and loaded
566
+ * (it is assumed that the `abcService` file knows how to register itself as a service).
567
+ *
568
+ * #### Lifecycle
569
+ *
570
+ * - The `lazyLoad` function is invoked if a transition is going to enter the state.
571
+ * - The function is invoked before the transition starts (using an `onBefore` transition hook).
572
+ * - The function is only invoked once; while the `lazyLoad` function is loading code, it will not be invoked again.
573
+ * For example, if the user double clicks a ui-sref, `lazyLoad` is only invoked once even though there were two transition attempts.
574
+ * Instead, the existing lazy load promise is re-used.
575
+ * - When the promise resolves successfully, the `lazyLoad` property is deleted from the state declaration.
576
+ * - If the promise resolves to a [[LazyLoadResult]] which has an array of `states`, those states are registered.
577
+ * - The original transition is retried (this time without the `lazyLoad` property present).
578
+ *
579
+ * - If the `lazyLoad` function fails, then the transition also fails.
580
+ * The failed transition (and the `lazyLoad` function) could potentially be retried by the user.
581
+ *
582
+ * ### Lazy loading state definitions (Future States)
583
+ *
584
+ * State definitions can also be lazy loaded.
585
+ * This might be desirable when building large, multi-module applications.
586
+ *
587
+ * To lazy load state definitions, a Future State should be registered as a placeholder.
588
+ * When the state definitions are lazy loaded, the Future State is deregistered.
589
+ *
590
+ * A future state can act as a placeholder for a single state, or for an entire module of states and substates.
591
+ * A future state should have:
592
+ *
593
+ * - A `name` which ends in `.**`.
594
+ * A future state's `name` property acts as a wildcard [[Glob]].
595
+ * It matches any state name that starts with the `name` (including child states that are not yet loaded).
596
+ * - A `url` prefix.
597
+ * A future state's `url` property acts as a wildcard.
598
+ * UI-Router matches all paths that begin with the `url`.
599
+ * It effectively appends `.*` to the internal regular expression.
600
+ * When the prefix matches, the future state will begin loading.
601
+ * - A `lazyLoad` function.
602
+ * This function should should return a Promise to lazy load the code for one or more [[StateDeclaration]] objects.
603
+ * It should return a [[LazyLoadResult]].
604
+ * Generally, one of the lazy loaded states should have the same name as the future state.
605
+ * The new state will then **replace the future state placeholder** in the registry.
606
+ *
607
+ * ### Additional resources
608
+ *
609
+ * For in depth information on lazy loading and Future States, see the [Lazy Loading Guide](https://ui-router.github.io/guides/lazyload).
610
+ *
611
+ * #### Example: states.js
612
+ * ```js
613
+ *
614
+ * // This child state is a lazy loaded future state
615
+ * // The `lazyLoad` function loads the final state definition
616
+ * {
617
+ * name: 'parent.**',
618
+ * url: '/parent',
619
+ * lazyLoad: () => import('./lazy.states.js')
620
+ * }
621
+ * ```
622
+ *
623
+ * #### Example: lazy.states.js
624
+ *
625
+ * This file is lazy loaded. It exports an array of states.
626
+ *
627
+ * ```js
628
+ * import {ChildComponent} from "./child.component.js";
629
+ * import {ParentComponent} from "./parent.component.js";
630
+ *
631
+ * // This fully defined state replaces the future state
632
+ * let parentState = {
633
+ * // the name should match the future state
634
+ * name: 'parent',
635
+ * url: '/parent/:parentId',
636
+ * component: ParentComponent,
637
+ * resolve: {
638
+ * parentData: ($transition$, ParentService) =>
639
+ * ParentService.get($transition$.params().parentId)
640
+ * }
641
+ * }
642
+ *
643
+ * let childState = {
644
+ * name: 'parent.child',
645
+ * url: '/child/:childId',
646
+ * params: {
647
+ * childId: "default"
648
+ * },
649
+ * resolve: {
650
+ * childData: ($transition$, ChildService) =>
651
+ * ChildService.get($transition$.params().childId)
652
+ * }
653
+ * };
654
+ *
655
+ * // This array of states will be registered by the lazyLoad hook
656
+ * let lazyLoadResults = {
657
+ * states: [ parentState, childState ]
658
+ * };
659
+ *
660
+ * export default lazyLoadResults;
661
+ * ```
662
+ *
663
+ * @param transition the [[Transition]] that is activating the future state
664
+ * @param state the [[StateDeclaration]] that the `lazyLoad` function is declared on
665
+ * @return a Promise to load the states.
666
+ * Optionally, if the promise resolves to a [[LazyLoadResult]],
667
+ * the states will be registered with the [[StateRegistry]].
668
+ */
669
+ lazyLoad?: (
670
+ transition: Transition,
671
+ state: StateDeclaration,
672
+ ) => Promise<LazyLoadResult>;
673
+ /**
674
+ * Marks all the state's parameters as `dynamic`.
675
+ *
676
+ * All parameters on the state will use this value for `dynamic` as a default.
677
+ * Individual parameters may override this default using [[ParamDeclaration.dynamic]] in the [[params]] block.
678
+ *
679
+ * Note: this value overrides the `dynamic` value on a custom parameter type ([[ParamTypeDefinition.dynamic]]).
680
+ */
681
+ dynamic?: boolean;
682
+ /**
683
+ * Marks all query parameters as [[ParamDeclaration.dynamic]]
684
+ *
685
+ * @deprecated use either [[dynamic]] or [[ParamDeclaration.dynamic]]
686
+ */
687
+ reloadOnSearch?: boolean;
666
688
  }
667
689
  /**
668
690
  * The return type of a [[StateDeclaration.lazyLoad]] function
@@ -672,37 +694,39 @@ export interface StateDeclaration {
672
694
  * of [[StateDeclaration]] objects will be automatically registered.
673
695
  */
674
696
  export interface LazyLoadResult {
675
- states?: StateDeclaration[];
697
+ states?: StateDeclaration[];
676
698
  }
677
699
  /**
678
700
  * An options object for [[StateService.href]]
679
701
  */
680
702
  export interface HrefOptions {
681
- /**
682
- * Defines what state to be "relative from"
683
- *
684
- * When a relative path is found (e.g `^` or `.bar`), defines which state to be relative from.
685
- */
686
- relative?: StateOrName;
687
- /**
688
- * If true, and if there is no url associated with the state provided in the
689
- * first parameter, then the constructed href url will be built from the first
690
- * ancestor which has a url.
691
- */
692
- lossy?: boolean;
693
- /**
694
- * If `true` will inherit parameters from the current parameter values.
695
- */
696
- inherit?: boolean;
697
- /**
698
- * If true will generate an absolute url, e.g. `http://www.example.com/fullurl`.
699
- */
700
- absolute?: boolean;
703
+ /**
704
+ * Defines what state to be "relative from"
705
+ *
706
+ * When a relative path is found (e.g `^` or `.bar`), defines which state to be relative from.
707
+ */
708
+ relative?: StateOrName;
709
+ /**
710
+ * If true, and if there is no url associated with the state provided in the
711
+ * first parameter, then the constructed href url will be built from the first
712
+ * ancestor which has a url.
713
+ */
714
+ lossy?: boolean;
715
+ /**
716
+ * If `true` will inherit parameters from the current parameter values.
717
+ */
718
+ inherit?: boolean;
719
+ /**
720
+ * If true will generate an absolute url, e.g. `http://www.example.com/fullurl`.
721
+ */
722
+ absolute?: boolean;
701
723
  }
702
724
  /**
703
725
  * Either a [[StateDeclaration]] or an ES6 class that implements [[StateDeclaration]]
704
726
  * The ES6 class constructor should have no arguments.
705
727
  */
706
- export declare type _StateDeclaration = StateDeclaration | {
707
- new (): StateDeclaration;
708
- };
728
+ export declare type _StateDeclaration =
729
+ | StateDeclaration
730
+ | {
731
+ new (): StateDeclaration;
732
+ };