@angular-wave/angular.ts 0.9.0 → 0.9.1

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 (208) hide show
  1. package/@types/core/scope/scope.d.ts +1 -4
  2. package/@types/interface.d.ts +17 -3
  3. package/@types/shared/interface.d.ts +17 -0
  4. package/@types/shared/utils.d.ts +4 -19
  5. package/dist/angular-ts.esm.js +29 -152
  6. package/dist/angular-ts.umd.js +29 -152
  7. package/dist/angular-ts.umd.min.js +1 -1
  8. package/docs/layouts/shortcodes/version.html +1 -1
  9. package/docs/static/typedoc/assets/hierarchy.js +1 -1
  10. package/docs/static/typedoc/assets/main.js +2 -2
  11. package/docs/static/typedoc/assets/navigation.js +1 -1
  12. package/docs/static/typedoc/assets/search.js +1 -1
  13. package/docs/static/typedoc/classes/Location.html +20 -20
  14. package/docs/static/typedoc/classes/LocationProvider.html +5 -5
  15. package/docs/static/typedoc/classes/LogProvider.html +3 -3
  16. package/docs/static/typedoc/classes/PubSub.html +21 -21
  17. package/docs/static/typedoc/classes/PubSubProvider.html +1 -1
  18. package/docs/static/typedoc/classes/TemplateCacheProvider.html +2 -2
  19. package/docs/static/typedoc/hierarchy.html +1 -1
  20. package/docs/static/typedoc/index.html +1 -1
  21. package/docs/static/typedoc/interfaces/ChangesObject.html +3 -3
  22. package/docs/static/typedoc/interfaces/ComponentOptions.html +8 -8
  23. package/docs/static/typedoc/interfaces/Controller.html +6 -6
  24. package/docs/static/typedoc/interfaces/DefaultPorts.html +1 -1
  25. package/docs/static/typedoc/interfaces/Directive.html +18 -18
  26. package/docs/static/typedoc/interfaces/DirectivePrePost.html +1 -1
  27. package/docs/static/typedoc/interfaces/Html5Mode.html +1 -1
  28. package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +7 -7
  29. package/docs/static/typedoc/interfaces/HttpService.html +21 -21
  30. package/docs/static/typedoc/interfaces/LogService.html +6 -6
  31. package/docs/static/typedoc/interfaces/NgModelController.html +15 -15
  32. package/docs/static/typedoc/interfaces/NgModelOptions.html +8 -8
  33. package/docs/static/typedoc/interfaces/Provider.html +17 -17
  34. package/docs/static/typedoc/interfaces/RequestConfig.html +15 -15
  35. package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +11 -11
  36. package/docs/static/typedoc/interfaces/ServiceProvider.html +1 -1
  37. package/docs/static/typedoc/interfaces/TemplateCache.html +1 -1
  38. package/docs/static/typedoc/interfaces/TranscludeFunctionObject.html +4 -4
  39. package/docs/static/typedoc/interfaces/UrlParts.html +4 -4
  40. package/docs/static/typedoc/types/AnnotatedFactory.html +1 -1
  41. package/docs/static/typedoc/types/CloneAttachFunction.html +1 -1
  42. package/docs/static/typedoc/types/ControllerConstructor.html +1 -1
  43. package/docs/static/typedoc/types/DirectiveCompileFn.html +1 -1
  44. package/docs/static/typedoc/types/DirectiveController.html +1 -1
  45. package/docs/static/typedoc/types/DirectiveFactoryFn.html +1 -1
  46. package/docs/static/typedoc/types/DirectiveLinkFn.html +1 -1
  47. package/docs/static/typedoc/types/Expression.html +1 -1
  48. package/docs/static/typedoc/types/FilterFactory.html +1 -1
  49. package/docs/static/typedoc/types/FilterFn.html +1 -1
  50. package/docs/static/typedoc/types/Injectable.html +1 -1
  51. package/docs/static/typedoc/types/InjectableFactory.html +1 -1
  52. package/docs/static/typedoc/types/LogCall.html +1 -1
  53. package/docs/static/typedoc/types/LogServiceFactory.html +1 -1
  54. package/docs/static/typedoc/types/OnChangesObject.html +1 -1
  55. package/docs/static/typedoc/types/SwapModeType.html +1 -1
  56. package/docs/static/typedoc/types/TController.html +1 -1
  57. package/docs/static/typedoc/types/UrlChangeListener.html +4 -4
  58. package/docs/static/typedoc/variables/SwapMode.html +10 -10
  59. package/legacy.d.ts +0 -82
  60. package/package.json +2 -2
  61. package/src/animations/animate-js.js +2 -1
  62. package/src/animations/animate-queue.js +7 -6
  63. package/src/core/scope/scope.js +8 -10
  64. package/src/directive/http/form-router-test.html +44 -0
  65. package/src/directive/options/options-example.html +7 -3
  66. package/src/directive/options/options.js +1 -0
  67. package/src/directive/options/options.spec.js +117 -170
  68. package/src/interface.ts +20 -3
  69. package/src/router/directives/view-directive.js +0 -1
  70. package/src/router/resolve/resolve-context.js +0 -19
  71. package/src/router/state/state-registry.js +3 -10
  72. package/src/router/state/state-service.js +5 -5
  73. package/src/router/transition/transition.js +1 -86
  74. package/src/router/view-hook.spec.js +1 -1
  75. package/src/shared/interface.ts +19 -0
  76. package/src/shared/utils.js +3 -12
  77. package/tsconfig.types.json +2 -2
  78. package/@types/angular.d.ts +0 -150
  79. package/@types/animations/animate-cache.d.ts +0 -50
  80. package/@types/animations/animate-children-directive.d.ts +0 -10
  81. package/@types/animations/animate-css-driver.d.ts +0 -18
  82. package/@types/animations/animate-css.d.ts +0 -18
  83. package/@types/animations/animate-js-driver.d.ts +0 -14
  84. package/@types/animations/animate-js.d.ts +0 -23
  85. package/@types/animations/animate-queue.d.ts +0 -28
  86. package/@types/animations/animate-runner.d.ts +0 -31
  87. package/@types/animations/animate-swap.d.ts +0 -9
  88. package/@types/animations/animate.d.ts +0 -450
  89. package/@types/animations/animation.d.ts +0 -14
  90. package/@types/animations/interface.d.ts +0 -17
  91. package/@types/animations/raf-scheduler.d.ts +0 -37
  92. package/@types/animations/shared.d.ts +0 -74
  93. package/@types/core/compile/compile.d.ts +0 -201
  94. package/@types/core/controller/controller.d.ts +0 -54
  95. package/@types/core/di/injector.d.ts +0 -22
  96. package/@types/core/filter/filter.d.ts +0 -23
  97. package/@types/core/interpolate/interpolate.d.ts +0 -38
  98. package/@types/core/parse/ast/ast-node.d.ts +0 -56
  99. package/@types/core/parse/ast/ast.d.ts +0 -164
  100. package/@types/core/parse/lexer/lexer.d.ts +0 -119
  101. package/@types/core/parse/lexer/token.d.ts +0 -17
  102. package/@types/core/parse/parse.d.ts +0 -33
  103. package/@types/core/parse/parser/parser.d.ts +0 -41
  104. package/@types/core/sanitize/interface.d.ts +0 -10
  105. package/@types/core/sanitize/sanitize-uri.d.ts +0 -40
  106. package/@types/directive/aria/aria.d.ts +0 -104
  107. package/@types/directive/attrs/attrs.d.ts +0 -8
  108. package/@types/directive/bind/bind.d.ts +0 -18
  109. package/@types/directive/channel/channel.d.ts +0 -10
  110. package/@types/directive/class/class.d.ts +0 -3
  111. package/@types/directive/cloak/cloak.d.ts +0 -4
  112. package/@types/directive/controller/controller.d.ts +0 -4
  113. package/@types/directive/events/events.d.ts +0 -21
  114. package/@types/directive/form/form.d.ts +0 -264
  115. package/@types/directive/http/http.d.ts +0 -46
  116. package/@types/directive/if/if.d.ts +0 -10
  117. package/@types/directive/include/include.d.ts +0 -28
  118. package/@types/directive/init/init.d.ts +0 -4
  119. package/@types/directive/input/input.d.ts +0 -70
  120. package/@types/directive/messages/messages.d.ts +0 -63
  121. package/@types/directive/model/model.d.ts +0 -515
  122. package/@types/directive/model-options/model-options.d.ts +0 -56
  123. package/@types/directive/non-bindable/non-bindable.d.ts +0 -4
  124. package/@types/directive/observe/observe.d.ts +0 -9
  125. package/@types/directive/options/options.d.ts +0 -13
  126. package/@types/directive/ref/ref.d.ts +0 -11
  127. package/@types/directive/repeat/repeat.d.ts +0 -11
  128. package/@types/directive/script/script.d.ts +0 -10
  129. package/@types/directive/select/select.d.ts +0 -15
  130. package/@types/directive/setter/setter.d.ts +0 -12
  131. package/@types/directive/show-hide/show-hide.d.ts +0 -19
  132. package/@types/directive/style/style.d.ts +0 -4
  133. package/@types/directive/switch/switch.d.ts +0 -18
  134. package/@types/directive/transclude/transclude.d.ts +0 -10
  135. package/@types/directive/validators/validators.d.ts +0 -149
  136. package/@types/filters/filter.d.ts +0 -4
  137. package/@types/filters/filters.d.ts +0 -38
  138. package/@types/filters/limit-to.d.ts +0 -4
  139. package/@types/filters/order-by.d.ts +0 -7
  140. package/@types/index.d.ts +0 -2
  141. package/@types/ng.d.ts +0 -8
  142. package/@types/router/common/trace.d.ts +0 -66
  143. package/@types/router/directives/state-directives.d.ts +0 -46
  144. package/@types/router/directives/view-directive.d.ts +0 -138
  145. package/@types/router/glob/glob.d.ts +0 -81
  146. package/@types/router/hooks/core-resolvables.d.ts +0 -2
  147. package/@types/router/hooks/ignored-transition.d.ts +0 -1
  148. package/@types/router/hooks/invalid-transition.d.ts +0 -1
  149. package/@types/router/hooks/lazy-load.d.ts +0 -42
  150. package/@types/router/hooks/on-enter-exit-retain.d.ts +0 -3
  151. package/@types/router/hooks/redirect-to.d.ts +0 -4
  152. package/@types/router/hooks/resolve.d.ts +0 -4
  153. package/@types/router/hooks/update-globals.d.ts +0 -1
  154. package/@types/router/hooks/url.d.ts +0 -5
  155. package/@types/router/hooks/views.d.ts +0 -5
  156. package/@types/router/params/interface.d.ts +0 -606
  157. package/@types/router/params/param-factory.d.ts +0 -16
  158. package/@types/router/params/param-type.d.ts +0 -59
  159. package/@types/router/params/param-types.d.ts +0 -36
  160. package/@types/router/params/param.d.ts +0 -71
  161. package/@types/router/params/state-params.d.ts +0 -12
  162. package/@types/router/path/path-node.d.ts +0 -38
  163. package/@types/router/path/path-utils.d.ts +0 -88
  164. package/@types/router/resolve/interface.d.ts +0 -200
  165. package/@types/router/resolve/resolvable.d.ts +0 -50
  166. package/@types/router/resolve/resolve-context.d.ts +0 -102
  167. package/@types/router/router.d.ts +0 -47
  168. package/@types/router/state/interface.d.ts +0 -983
  169. package/@types/router/state/state-builder.d.ts +0 -95
  170. package/@types/router/state/state-matcher.d.ts +0 -7
  171. package/@types/router/state/state-object.d.ts +0 -83
  172. package/@types/router/state/state-queue-manager.d.ts +0 -29
  173. package/@types/router/state/state-registry.d.ts +0 -134
  174. package/@types/router/state/state-service.d.ts +0 -419
  175. package/@types/router/state/target-state.d.ts +0 -102
  176. package/@types/router/state/views.d.ts +0 -58
  177. package/@types/router/state-filters.d.ts +0 -39
  178. package/@types/router/template-factory.d.ts +0 -117
  179. package/@types/router/transition/hook-builder.d.ts +0 -45
  180. package/@types/router/transition/hook-registry.d.ts +0 -102
  181. package/@types/router/transition/interface.d.ts +0 -880
  182. package/@types/router/transition/reject-factory.d.ts +0 -43
  183. package/@types/router/transition/transition-event-type.d.ts +0 -24
  184. package/@types/router/transition/transition-hook.d.ts +0 -86
  185. package/@types/router/transition/transition-service.d.ts +0 -116
  186. package/@types/router/transition/transition.d.ts +0 -396
  187. package/@types/router/url/url-config.d.ts +0 -99
  188. package/@types/router/url/url-matcher.d.ts +0 -174
  189. package/@types/router/url/url-rule.d.ts +0 -161
  190. package/@types/router/url/url-rules.d.ts +0 -249
  191. package/@types/router/url/url-service.d.ts +0 -254
  192. package/@types/router/view/interface.d.ts +0 -44
  193. package/@types/router/view/view.d.ts +0 -149
  194. package/@types/router/view-scroll.d.ts +0 -10
  195. package/@types/services/anchor-scroll.d.ts +0 -25
  196. package/@types/services/cookie-reader.d.ts +0 -4
  197. package/@types/services/http/http.d.ts +0 -134
  198. package/@types/services/http-backend/http-backend.d.ts +0 -58
  199. package/@types/services/sce/sce.d.ts +0 -238
  200. package/@types/services/template-request.d.ts +0 -55
  201. package/@types/shared/common.d.ts +0 -197
  202. package/@types/shared/hof.d.ts +0 -108
  203. package/@types/shared/predicates.d.ts +0 -17
  204. package/@types/shared/queue.d.ts +0 -64
  205. package/@types/shared/strings.d.ts +0 -58
  206. package/@types/shared/test-utils.d.ts +0 -18
  207. package/docs/static/typedoc/classes/NgModule.html +0 -32
  208. package/src/router/params/README.md +0 -8
@@ -1,880 +0,0 @@
1
- import { StateDeclaration } from "../state/interface.ts";
2
- import { PredicateBinary } from "../../shared/interface.ts";
3
- import { Transition } from "./transition.js";
4
- import { StateObject } from "../state/state-object.js";
5
- import { PathNode } from "../path/path-node.js";
6
- import { TargetState } from "../state/target-state.js";
7
- import { RegisteredHook } from "./hook-registry.js";
8
- /**
9
- * The TransitionOptions object can be used to change the behavior of a transition.
10
- *
11
- * It is passed as the third argument to [[StateService.go]], [[StateService.transitionTo]].
12
- * It can also be used with a `uiSref`.
13
- */
14
- export interface TransitionOptions {
15
- /**
16
- * This option changes how the Transition interacts with the browser's location bar (URL).
17
- *
18
- * - If `true`, it will update the url in the location bar.
19
- * - If `false`, it will not update the url in the location bar.
20
- * - If it is the string `"replace"`, it will update the url and also replace the last history record.
21
- *
22
- * @default `true`
23
- */
24
- location?: boolean | "replace";
25
- /**
26
- * When transitioning to relative path (e.g '`^`'), this option defines which state to be relative from.
27
- * @default `$state.current`
28
- */
29
- relative?: string | StateDeclaration | StateObject;
30
- /**
31
- * This option sets whether or not the transition's parameter values should be inherited from
32
- * the current parameter values.
33
- *
34
- * - If `true`, it will inherit parameter values from the current parameter values.
35
- * - If `false`, only the parameters which are provided to `transitionTo` will be used.
36
- *
37
- * @default `true`
38
- */
39
- inherit?: boolean;
40
- /**
41
- * @deprecated
42
- */
43
- notify?: boolean;
44
- /**
45
- * This option may be used to force states which are currently active to reload.
46
- *
47
- * During a normal transition, a state is "retained" if:
48
- * - It was previously active
49
- * - The state's parameter values have not changed
50
- * - All the parent states' parameter values have not changed
51
- *
52
- * Forcing a reload of a state will cause it to be exited and entered, which will:
53
- * - Refetch that state's resolve data
54
- * - Exit the state (onExit hook)
55
- * - Re-enter the state (onEnter hook)
56
- * - Re-render the views (controllers and templates)
57
- *
58
- * - When `true`, the destination state (and all parent states) will be reloaded.
59
- * - When it is a string and is the name of a state, or when it is a State object,
60
- * that state and any children states will be reloaded.
61
- *
62
- * @default `false`
63
- */
64
- reload?: boolean | string | StateDeclaration | StateObject;
65
- /**
66
- * You can define your own Transition Options inside this property and use them, e.g., from a Transition Hook
67
- */
68
- custom?: any;
69
- /**
70
- * This option may be used to cancel the active transition (if one is active) in favour of the this one.
71
- * This is the default behaviour or ui-router.
72
- *
73
- *
74
- * - When `true`, the active transition will be canceled and new transition will begin.
75
- * - when `false`, the transition will be canceled if a transition is already running. This can be useful in cases where
76
- * you only want to navigate to a different state if you are not already navigating somewhere.
77
- *
78
- * @default `true`
79
- */
80
- supercede?: boolean;
81
- /** @internal */
82
- reloadState?: StateObject;
83
- /** @internal
84
- * If this transition is a redirect, this property should be the original Transition (which was redirected to this one)
85
- */
86
- redirectedFrom?: Transition;
87
- /** @internal */
88
- current?: () => Transition;
89
- /** @internal */
90
- source?: "sref" | "url" | "redirect" | "otherwise" | "unknown";
91
- }
92
- export interface TransitionHookOptions {
93
- current?: () => Transition;
94
- transition?: Transition;
95
- hookType?: string;
96
- target?: any;
97
- traceData?: any;
98
- bind?: any;
99
- stateHook?: boolean;
100
- }
101
- /**
102
- * TreeChanges encapsulates the various Paths that are involved in a Transition.
103
- *
104
- * Get a TreeChanges object using [[Transition.treeChanges]]
105
- *
106
- * A UI-Router Transition is from one Path in a State Tree to another Path. For a given Transition,
107
- * this object stores the "to" and "from" paths, as well as subsets of those: the "retained",
108
- * "exiting" and "entering" paths.
109
- *
110
- * Each path in TreeChanges is an array of [[PathNode]] objects. Each PathNode in the array corresponds to a portion
111
- * of a nested state.
112
- *
113
- * For example, if you had a nested state named `foo.bar.baz`, it would have three
114
- * portions, `foo, bar, baz`. If you transitioned **to** `foo.bar.baz` and inspected the [[TreeChanges.to]]
115
- * Path, you would find a node in the array for each portion: `foo`, `bar`, and `baz`.
116
- *
117
- * ---
118
- *
119
- * @todo show visual state tree
120
- */
121
- export interface TreeChanges {
122
- /** @nodoc */
123
- [key: string]: PathNode[] | undefined;
124
- /** The path of nodes in the state tree that the transition is coming *from* */
125
- from: PathNode[];
126
- /** The path of nodes in the state tree that the transition is going *to* */
127
- to: PathNode[];
128
- /**
129
- * The path of active nodes that the transition is retaining.
130
- *
131
- * These nodes are neither exited, nor entered.
132
- * Before and after the transition is successful, these nodes are active.
133
- */
134
- retained: PathNode[];
135
- /**
136
- * The path of active nodes that the transition is retaining with updated "to params" applied.
137
- *
138
- * These nodes are neither exited, nor entered.
139
- * Before and after the transition is successful, these nodes are active.
140
- *
141
- * This is a shallow copy of [[retained]], but with new (dynamic) parameter values from [[to]] applied.
142
- */
143
- retainedWithToParams: PathNode[];
144
- /**
145
- * The path of previously active nodes that the transition is exiting.
146
- *
147
- * After the Transition is successful, these nodes are no longer active.
148
- *
149
- * Note that a state that is being reloaded (due to parameter values changing, or `reload: true`) may be in both the
150
- * `exiting` and `entering` paths.
151
- */
152
- exiting: PathNode[];
153
- /**
154
- * The path of nodes that the transition is entering.
155
- *
156
- * After the Transition is successful, these nodes will be active.
157
- * Because they are entering, they have their resolves fetched, `onEnter` hooks run, and their views
158
- * (component(s) or controller(s)+template(s)) refreshed.
159
- *
160
- * Note that a state that is reloaded (due to parameter values changing, or `reload: true`) may be in both the
161
- * `exiting` and `entering` paths.
162
- */
163
- entering: PathNode[];
164
- }
165
- export type IHookRegistration = (
166
- matchCriteria: HookMatchCriteria,
167
- callback: HookFn,
168
- options?: HookRegOptions,
169
- ) => Function;
170
- /**
171
- * The signature for Transition Hooks.
172
- *
173
- * Transition hooks are callback functions that hook into the lifecycle of transitions.
174
- * As a transition runs, it reaches certain lifecycle events.
175
- * As each event occurs, the hooks which are registered for the event are called (in priority order).
176
- *
177
- * A transition hook may alter a Transition by returning a [[HookResult]].
178
- *
179
- * #### See:
180
- *
181
- * - [[IHookRegistry.onBefore]]
182
- * - [[IHookRegistry.onStart]]
183
- * - [[IHookRegistry.onFinish]]
184
- * - [[IHookRegistry.onSuccess]]
185
- * - [[IHookRegistry.onError]]
186
- *
187
- * @param transition the current [[Transition]]
188
- * @param injector (for ng1 or ng2 only) the injector service
189
- *
190
- * @returns a [[HookResult]] which may alter the transition
191
- *
192
- */
193
- export interface TransitionHookFn {
194
- (transition: Transition): HookResult;
195
- }
196
- /**
197
- * The signature for State Transition Hooks.
198
- *
199
- * State hooks are registered as onEnter/onRetain/onExit in state declarations.
200
- * State hooks can additionally be injected with $transitions and $states for
201
- * the current [[Transition]] and [[StateObject]] in the transition.
202
- *
203
- * Transition State Hooks are callback functions that hook into the lifecycle events of specific states during a transition.
204
- * As a transition runs, it may exit some states, retain (keep) states, and enter states.
205
- * As each lifecycle event occurs, the hooks which are registered for the event and that state are called (in priority order).
206
- *
207
- * #### See also:
208
- *
209
- * - [[IHookRegistry.onExit]]
210
- * - [[IHookRegistry.onRetain]]
211
- * - [[IHookRegistry.onEnter]]
212
- *
213
- * #### Example:
214
- * ```js
215
- * onEnter: function() { console.log('Entering'); }
216
- * ```
217
- *
218
- * Not minification-safe
219
- * ```js
220
- * onRetain: function($state$) { console.log('Retained ' + $state$.name); }
221
- * ```
222
- *
223
- * Annotated for minification-safety
224
- * ```js
225
- * onExit: [ '$transition$', '$state', function($transition$, $state) {
226
- * // always redirect to 'foo' state when being exited
227
- * if ($transition$.to().name !== 'foo') {
228
- * return $state.target('foo');
229
- * }
230
- * } ]
231
- * ```
232
- *
233
- * @returns an optional [[HookResult]] which may alter the transition
234
- */
235
- export interface TransitionStateHookFn {
236
- (...injectables: any[]): HookResult;
237
- }
238
- /**
239
- * The signature for Transition onCreate Hooks.
240
- *
241
- * Transition onCreate Hooks are callbacks that allow customization or preprocessing of
242
- * a Transition before it is returned from [[TransitionService.create]]
243
- *
244
- * @param transition the [[Transition]] that was just created
245
- * @return a [[Transition]] which will then be returned from [[TransitionService.create]]
246
- */
247
- export interface TransitionCreateHookFn {
248
- (transition: Transition): void;
249
- }
250
- export type HookFn =
251
- | TransitionHookFn
252
- | TransitionStateHookFn
253
- | TransitionCreateHookFn;
254
- /**
255
- * The return value of a [[TransitionHookFn]] or [[TransitionStateHookFn]]
256
- *
257
- * When returned from a [[TransitionHookFn]] or [[TransitionStateHookFn]], these values alter the running [[Transition]]:
258
- *
259
- * - `false`: the transition will be cancelled.
260
- * - [[TargetState]]: the transition will be redirected to the new target state (see: [[StateService.target]])
261
- * - `Promise`: the transition will wait for the promise to resolve or reject
262
- * - If the promise is rejected (or resolves to `false`), the transition will be cancelled
263
- * - If the promise resolves to a [[TargetState]], the transition will be redirected
264
- * - If the promise resolves to anything else, the transition will resume
265
- * - Anything else: the transition will resume
266
- */
267
- export type HookResult =
268
- | boolean
269
- | TargetState
270
- | void
271
- | Promise<boolean | TargetState | void>;
272
- /**
273
- * These options may be provided when registering a Transition Hook (such as `onStart`)
274
- */
275
- export interface HookRegOptions {
276
- /**
277
- * Sets the priority of the registered hook
278
- *
279
- * Hooks of the same type (onBefore, onStart, etc) are invoked in priority order. A hook with a higher priority
280
- * is invoked before a hook with a lower priority.
281
- *
282
- * The default hook priority is 0
283
- */
284
- priority?: number;
285
- /**
286
- * Specifies what `this` is bound to during hook invocation.
287
- */
288
- bind?: any;
289
- /**
290
- * Limits the number of times that the hook will be invoked.
291
- * Once the hook has been invoked this many times, it is automatically deregistered.
292
- */
293
- invokeLimit?: number;
294
- }
295
- /**
296
- * This interface specifies the api for registering Transition Hooks. Both the
297
- * [[TransitionService]] and also the [[Transition]] object itself implement this interface.
298
- * Note: the Transition object only allows hooks to be registered before the Transition is started.
299
- */
300
- export interface IHookRegistry {
301
- /** @internal place to store the hooks */
302
- _registeredHooks: {
303
- [key: string]: RegisteredHook[];
304
- };
305
- /**
306
- * Registers a [[TransitionHookFn]], called *before a transition starts*.
307
- *
308
- * Registers a transition lifecycle hook, which is invoked before a transition even begins.
309
- * This hook can be useful to implement logic which prevents a transition from even starting, such
310
- * as authentication, redirection
311
- *
312
- * See [[TransitionHookFn]] for the signature of the function.
313
- *
314
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
315
- * To match all Transitions, use an empty criteria object `{}`.
316
- *
317
- * ### Lifecycle
318
- *
319
- * `onBefore` hooks are invoked *before a Transition starts*.
320
- * No resolves have been fetched yet.
321
- * Each `onBefore` hook is invoked synchronously, in the same call stack as [[StateService.transitionTo]].
322
- * The registered `onBefore` hooks are invoked in priority order.
323
- *
324
- * Note: during the `onBefore` phase, additional hooks can be added to the specific [[Transition]] instance.
325
- * These "on-the-fly" hooks only affect the currently running transition..
326
- *
327
- * ### Return value
328
- *
329
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
330
- * See [[HookResult]] for more information.
331
- *
332
- * If any hook modifies the transition *synchronously* (by throwing, returning `false`, or returning
333
- * a [[TargetState]]), the remainder of the hooks are skipped.
334
- * If a hook returns a promise, the remainder of the `onBefore` hooks are still invoked synchronously.
335
- * All promises are resolved, and processed asynchronously before the `onStart` phase of the Transition.
336
- *
337
- * ### Examples
338
- *
339
- * #### Default Substate
340
- *
341
- * This example redirects any transition from 'home' to 'home.dashboard'. This is commonly referred to as a
342
- * "default substate".
343
- *
344
- * @example
345
- * ```js
346
- * // ng2
347
- * transitionService.onBefore({ to: 'home' }, (trans: Transition) =>
348
- * trans.router.stateService.target("home.dashboard"));
349
- * ```
350
- *
351
- * #### Data Driven Default Substate
352
- *
353
- * This example provides data-driven default substate functionality. It matches on a transition to any state
354
- * which has `defaultSubstate: "some.sub.state"` defined. See: [[Transition.to]] which returns the "to state"
355
- * definition.
356
- *
357
- * @example
358
- * ```js
359
- * // ng1
360
- * // state declaration
361
- * {
362
- * name: 'home',
363
- * template: '<div ui-view/>',
364
- * defaultSubstate: 'home.dashboard'
365
- * }
366
- *
367
- * var criteria = {
368
- * to: function(state) {
369
- * return state.defaultSubstate != null;
370
- * }
371
- * }
372
- *
373
- * $transitions.onBefore(criteria, function(trans: Transition) {
374
- * var substate = trans.to().defaultSubstate;
375
- * return trans.router.stateService.target(substate);
376
- * });
377
- * ```
378
- *
379
- *
380
- * #### Require authentication
381
- *
382
- * This example cancels a transition to a state which requires authentication, if the user is not currently authenticated.
383
- *
384
- * This example assumes a state tree where all states which require authentication are children of a parent `'requireauth'` state.
385
- * This example assumes `MyAuthService` synchronously returns a boolean from `isAuthenticated()`.
386
- *
387
- * #### Example:
388
- * ```js
389
- * // ng1
390
- * $transitions.onBefore( { to: 'requireauth.**' }, function(trans) {
391
- * var myAuthService = trans.injector().get('MyAuthService');
392
- * // If isAuthenticated returns false, the transition is cancelled.
393
- * return myAuthService.isAuthenticated();
394
- * });
395
- * ```
396
- *
397
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
398
- * @param callback the hook function which will be invoked.
399
- * @returns a function which deregisters the hook.
400
- */
401
- onBefore(
402
- matchCriteria: HookMatchCriteria,
403
- callback: TransitionHookFn,
404
- options?: HookRegOptions,
405
- ): Function;
406
- /**
407
- * Registers a [[TransitionHookFn]], called when a transition starts.
408
- *
409
- * Registers a transition lifecycle hook, which is invoked as a transition starts running.
410
- * This hook can be useful to perform some asynchronous action before completing a transition.
411
- *
412
- * See [[TransitionHookFn]] for the signature of the function.
413
- *
414
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
415
- * To match all Transitions, use an empty criteria object `{}`.
416
- *
417
- * ### Lifecycle
418
- *
419
- * `onStart` hooks are invoked asynchronously when the Transition starts running.
420
- * This happens after the `onBefore` phase is complete.
421
- * At this point, the Transition has not yet exited nor entered any states.
422
- * The registered `onStart` hooks are invoked in priority order.
423
- *
424
- * Note: A built-in `onStart` hook with high priority is used to fetch any eager resolve data.
425
- *
426
- * ### Return value
427
- *
428
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
429
- * See [[HookResult]] for more information.
430
- *
431
- * ### Example
432
- *
433
- * #### Login during transition
434
- *
435
- * This example intercepts any transition to a state which requires authentication, when the user is
436
- * not currently authenticated. It allows the user to authenticate asynchronously, then resumes the
437
- * transition. If the user did not authenticate successfully, it redirects to the "guest" state, which
438
- * does not require authentication.
439
- *
440
- * This example assumes:
441
- * - a state tree where all states which require authentication are children of a parent `'auth'` state.
442
- * - `MyAuthService.isAuthenticated()` synchronously returns a boolean.
443
- * - `MyAuthService.authenticate()` presents a login dialog, and returns a promise which is resolved
444
- * or rejected, whether or not the login attempt was successful.
445
- *
446
- * #### Example:
447
- * ```js
448
- * // ng1
449
- * $transitions.onStart( { to: 'auth.**' }, function(trans) {
450
- * var $state = trans.router.stateService;
451
- * var MyAuthService = trans.injector().get('MyAuthService');
452
- *
453
- * // If the user is not authenticated
454
- * if (!MyAuthService.isAuthenticated()) {
455
- *
456
- * // Then return a promise for a successful login.
457
- * // The transition will wait for this promise to settle
458
- *
459
- * return MyAuthService.authenticate().catch(function() {
460
- *
461
- * // If the authenticate() method failed for whatever reason,
462
- * // redirect to a 'guest' state which doesn't require auth.
463
- * return $state.target("guest");
464
- * });
465
- * }
466
- * });
467
- * ```
468
- *
469
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
470
- * @param callback the hook function which will be injected and invoked.
471
- * @returns a function which deregisters the hook.
472
- */
473
- onStart(
474
- matchCriteria: HookMatchCriteria,
475
- callback: TransitionHookFn,
476
- options?: HookRegOptions,
477
- ): Function;
478
- /**
479
- * Registers a [[TransitionStateHookFn]], called when a specific state is entered.
480
- *
481
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being entered.
482
- *
483
- * Since this hook is run only when the specific state is being *entered*, it can be useful for
484
- * performing tasks when entering a submodule/feature area such as initializing a stateful service,
485
- * or for guarding access to a submodule/feature area.
486
- *
487
- * See [[TransitionStateHookFn]] for the signature of the function.
488
- *
489
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
490
- * `onEnter` hooks generally specify `{ entering: 'somestate' }`.
491
- * To match all Transitions, use an empty criteria object `{}`.
492
- *
493
- * ### Lifecycle
494
- *
495
- * `onEnter` hooks are invoked when the Transition is entering a state.
496
- * States are entered after the `onRetain` phase is complete.
497
- * If more than one state is being entered, the parent state is entered first.
498
- * The registered `onEnter` hooks for a state are invoked in priority order.
499
- *
500
- * Note: A built-in `onEnter` hook with high priority is used to fetch lazy resolve data for states being entered.
501
- *
502
- * ### Return value
503
- *
504
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
505
- * See [[HookResult]] for more information.
506
- *
507
- * ### Inside a state declaration
508
- *
509
- * Instead of registering `onEnter` hooks using the [[TransitionService]], you may define an `onEnter` hook
510
- * directly on a state declaration (see: [[StateDeclaration.onEnter]]).
511
- *
512
- *
513
- * ### Examples
514
- *
515
- * #### Audit Log
516
- *
517
- * This example uses a service to log that a user has entered the admin section of an app.
518
- * This assumes that there are substates of the "admin" state, such as "admin.users", "admin.pages", etc.
519
- * @example
520
- * ```
521
- *
522
- * $transitions.onEnter({ entering: 'admin' }, function(transition, state) {
523
- * var AuditService = trans.injector().get('AuditService');
524
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
525
- * }
526
- * ```
527
- *
528
- * #### Audit Log (inside a state declaration)
529
- *
530
- * The `onEnter` inside this state declaration is syntactic sugar for the previous Audit Log example.
531
- * ```
532
- * {
533
- * name: 'admin',
534
- * component: 'admin',
535
- * onEnter: function($transition$, $state$) {
536
- * var AuditService = $transition$.injector().get('AuditService');
537
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
538
- * }
539
- * }
540
- * ```
541
- *
542
- * Note: A state declaration's `onEnter` function is injected for Angular 1 only.
543
- *
544
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
545
- * @param callback the hook function which will be injected and invoked.
546
- * @returns a function which deregisters the hook.
547
- */
548
- onEnter(
549
- matchCriteria: HookMatchCriteria,
550
- callback: TransitionStateHookFn,
551
- options?: HookRegOptions,
552
- ): Function;
553
- /**
554
- * Registers a [[TransitionStateHookFn]], called when a specific state is retained/kept.
555
- *
556
- * Registers a lifecycle hook, which is invoked (during a transition) for
557
- * a specific state that was previously active will remain active (is not being entered nor exited).
558
- *
559
- * This hook is invoked when a state is "retained" or "kept".
560
- * It means the transition is coming *from* a substate of the retained state *to* a substate of the retained state.
561
- * This hook can be used to perform actions when the user moves from one substate to another, such as between steps in a wizard.
562
- *
563
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
564
- * `onRetain` hooks generally specify `{ retained: 'somestate' }`.
565
- * To match all Transitions, use an empty criteria object `{}`.
566
- *
567
- * ### Lifecycle
568
- *
569
- * `onRetain` hooks are invoked after any `onExit` hooks have been fired.
570
- * If more than one state is retained, the child states' `onRetain` hooks are invoked first.
571
- * The registered `onRetain` hooks for a state are invoked in priority order.
572
- *
573
- * ### Return value
574
- *
575
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
576
- * See [[HookResult]] for more information.
577
- *
578
- * ### Inside a state declaration
579
- *
580
- * Instead of registering `onRetain` hooks using the [[TransitionService]], you may define an `onRetain` hook
581
- * directly on a state declaration (see: [[StateDeclaration.onRetain]]).
582
- *
583
- * Note: A state declaration's `onRetain` function is injected for Angular 1 only.
584
- *
585
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
586
- * @param callback the hook function which will be injected and invoked.
587
- * @returns a function which deregisters the hook.
588
- */
589
- onRetain(
590
- matchCriteria: HookMatchCriteria,
591
- callback: TransitionStateHookFn,
592
- options?: HookRegOptions,
593
- ): Function;
594
- /**
595
- * Registers a [[TransitionStateHookFn]], called when a specific state is exited.
596
- *
597
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being exited.
598
- *
599
- * Since this hook is run only when the specific state is being *exited*, it can be useful for
600
- * performing tasks when leaving a submodule/feature area such as cleaning up a stateful service,
601
- * or for preventing the user from leaving a state or submodule until some criteria is satisfied.
602
- *
603
- * See [[TransitionStateHookFn]] for the signature of the function.
604
- *
605
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
606
- * `onExit` hooks generally specify `{ exiting: 'somestate' }`.
607
- * To match all Transitions, use an empty criteria object `{}`.
608
- *
609
- * ### Lifecycle
610
- *
611
- * `onExit` hooks are invoked when the Transition is exiting a state.
612
- * States are exited after any `onStart` phase is complete.
613
- * If more than one state is being exited, the child states are exited first.
614
- * The registered `onExit` hooks for a state are invoked in priority order.
615
- *
616
- * ### Return value
617
- *
618
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
619
- * See [[HookResult]] for more information.
620
- *
621
- * ### Inside a state declaration
622
- *
623
- * Instead of registering `onExit` hooks using the [[TransitionService]], you may define an `onExit` hook
624
- * directly on a state declaration (see: [[StateDeclaration.onExit]]).
625
- *
626
- * Note: A state declaration's `onExit` function is injected for Angular 1 only.
627
- *
628
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
629
- * @param callback the hook function which will be injected and invoked.
630
- * @returns a function which deregisters the hook.
631
- */
632
- onExit(
633
- matchCriteria: HookMatchCriteria,
634
- callback: TransitionStateHookFn,
635
- options?: HookRegOptions,
636
- ): Function;
637
- /**
638
- * Registers a [[TransitionHookFn]], called *just before a transition finishes*.
639
- *
640
- * Registers a transition lifecycle hook, which is invoked just before a transition finishes.
641
- * This hook is a last chance to cancel or redirect a transition.
642
- *
643
- * See [[TransitionHookFn]] for the signature of the function.
644
- *
645
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
646
- * To match all Transitions, use an empty criteria object `{}`.
647
- *
648
- * ### Lifecycle
649
- *
650
- * `onFinish` hooks are invoked after the `onEnter` phase is complete.
651
- * These hooks are invoked just before the transition is "committed".
652
- * Each hook is invoked in priority order.
653
- *
654
- * ### Return value
655
- *
656
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
657
- * See [[HookResult]] for more information.
658
- *
659
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
660
- * @param callback the hook function which will be injected and invoked.
661
- * @returns a function which deregisters the hook.
662
- */
663
- onFinish(
664
- matchCriteria: HookMatchCriteria,
665
- callback: TransitionHookFn,
666
- options?: HookRegOptions,
667
- ): Function;
668
- /**
669
- * Registers a [[TransitionHookFn]], called after a successful transition completed.
670
- *
671
- * Registers a transition lifecycle hook, which is invoked after a transition successfully completes.
672
- *
673
- * See [[TransitionHookFn]] for the signature of the function.
674
- *
675
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
676
- * To match all Transitions, use an empty criteria object `{}`.
677
- *
678
- * ### Lifecycle
679
- *
680
- * `onSuccess` hooks are chained off the Transition's promise (see [[Transition.promise]]).
681
- * If the Transition is successful and its promise is resolved, then the `onSuccess` hooks are invoked.
682
- * Since these hooks are run after the transition is over, their return value is ignored.
683
- * The `onSuccess` hooks are invoked in priority order.
684
- *
685
- * ### Return value
686
- *
687
- * Since the Transition is already completed, the hook's return value is ignored
688
- *
689
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
690
- * @param callback the hook function which will be injected and invoked.
691
- * @returns a function which deregisters the hook.
692
- */
693
- onSuccess(
694
- matchCriteria: HookMatchCriteria,
695
- callback: TransitionHookFn,
696
- options?: HookRegOptions,
697
- ): Function;
698
- /**
699
- * Registers a [[TransitionHookFn]], called after a transition has errored.
700
- *
701
- * Registers a transition lifecycle hook, which is invoked after a transition has been rejected for any reason.
702
- *
703
- * See [[TransitionHookFn]] for the signature of the function.
704
- *
705
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
706
- * To match all Transitions, use an empty criteria object `{}`.
707
- *
708
- * ### Lifecycle
709
- *
710
- * The `onError` hooks are chained off the Transition's promise (see [[Transition.promise]]).
711
- * If a Transition fails, its promise is rejected and the `onError` hooks are invoked.
712
- * The `onError` hooks are invoked in priority order.
713
- *
714
- * Since these hooks are run after the transition is over, their return value is ignored.
715
- *
716
- * A transition "errors" if it was started, but failed to complete (for any reason).
717
- * A *non-exhaustive list* of reasons a transition can error:
718
- *
719
- * - A transition was cancelled because a new transition started while it was still running (`Transition superseded`)
720
- * - A transition was cancelled by a Transition Hook returning false
721
- * - A transition was redirected by a Transition Hook returning a [[TargetState]]
722
- * - A Transition Hook or resolve function threw an error
723
- * - A Transition Hook returned a rejected promise
724
- * - A resolve function returned a rejected promise
725
- *
726
- * To check the failure reason, inspect the return value of [[Transition.error]].
727
- *
728
- * Note: `onError` should be used for targeted error handling, or error recovery.
729
- * For simple catch-all error reporting, use [[StateService.defaultErrorHandler]].
730
- *
731
- * ### Return value
732
- *
733
- * Since the Transition is already completed, the hook's return value is ignored
734
- *
735
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
736
- * @param callback the hook function which will be injected and invoked.
737
- * @returns a function which deregisters the hook.
738
- */
739
- onError(
740
- matchCriteria: HookMatchCriteria,
741
- callback: TransitionHookFn,
742
- options?: HookRegOptions,
743
- ): Function;
744
- /**
745
- * Returns all the registered hooks of a given `hookName` type
746
- *
747
- * #### Example:
748
- * ```
749
- * $transitions.getHooks("onEnter")
750
- * ```
751
- */
752
- getHooks(hookName: string): RegisteredHook[];
753
- }
754
- /** A predicate type which tests if a [[StateObject]] and [[Transition]] passes some test. Returns a boolean. */
755
- export type IStateMatch = PredicateBinary<StateObject, Transition>;
756
- /**
757
- * This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
758
- * based on the Transition's "to state" and "from state".
759
- *
760
- * Each property (`to`, `from`, `exiting`, `retained`, and `entering`) can be a state [[Glob]] string,
761
- * a boolean, or a function that takes a state and returns a boolean (see [[HookMatchCriterion]])
762
- *
763
- * All properties are optional. If any property is omitted, it is replaced with the value `true`, and always matches.
764
- * To match any transition, use an empty criteria object `{}`.
765
- *
766
- * #### Example:
767
- * ```js
768
- * // This matches a transition coming from the `parent` state and going to the `parent.child` state.
769
- * var match = {
770
- * to: 'parent',
771
- * from: 'parent.child'
772
- * }
773
- * ```
774
- *
775
- * #### Example:
776
- * ```js
777
- * // This matches a transition coming from any substate of `parent` and going directly to the `parent` state.
778
- * var match = {
779
- * to: 'parent',
780
- * from: 'parent.**'
781
- * }
782
- * ```
783
- *
784
- * #### Example:
785
- * ```js
786
- * // This matches a transition coming from any state and going to any substate of `mymodule`
787
- * var match = {
788
- * to: 'mymodule.**'
789
- * }
790
- * ```
791
- *
792
- * #### Example:
793
- * ```js
794
- * // This matches a transition coming from any state and going to any state that has `data.authRequired`
795
- * // set to a truthy value.
796
- * var match = {
797
- * to: function(state) {
798
- * return state.data != null && state.data.authRequired === true;
799
- * }
800
- * }
801
- * ```
802
- * #### Example:
803
- * ```js
804
- * // This will match when route is just entered (initial load) or when the state is hard-refreshed
805
- * // by specifying `{refresh: true}` as transition options.
806
- * var match = {
807
- * from: (state, transition) => state.self.name === '' || transition.options().reload
808
- * }
809
- * ```
810
- *
811
- * #### Example:
812
- * ```js
813
- * // This matches a transition that is exiting `parent.child`
814
- * var match = {
815
- * exiting: 'parent.child'
816
- * }
817
- * ```
818
- */
819
- export interface HookMatchCriteria {
820
- [key: string]: HookMatchCriterion | undefined;
821
- /** A [[HookMatchCriterion]] to match the destination state */
822
- to?: HookMatchCriterion;
823
- /** A [[HookMatchCriterion]] to match the original (from) state */
824
- from?: HookMatchCriterion;
825
- /** A [[HookMatchCriterion]] to match any state that would be exiting */
826
- exiting?: HookMatchCriterion;
827
- /** A [[HookMatchCriterion]] to match any state that would be retained */
828
- retained?: HookMatchCriterion;
829
- /** A [[HookMatchCriterion]] to match any state that would be entering */
830
- entering?: HookMatchCriterion;
831
- }
832
- export interface IMatchingNodes {
833
- [key: string]: PathNode[];
834
- to: PathNode[];
835
- from: PathNode[];
836
- exiting: PathNode[];
837
- retained: PathNode[];
838
- entering: PathNode[];
839
- }
840
- /** @internal */
841
- export interface RegisteredHooks {
842
- [key: string]: RegisteredHook[];
843
- }
844
- /** @internal */
845
- export interface PathTypes {
846
- [key: string]: PathType;
847
- to: PathType;
848
- from: PathType;
849
- exiting: PathType;
850
- retained: PathType;
851
- entering: PathType;
852
- }
853
- /** @internal */
854
- export interface PathType {
855
- name: string;
856
- scope: TransitionHookScope;
857
- }
858
- /**
859
- * Hook Criterion used to match a transition.
860
- *
861
- * A [[Glob]] string that matches the name of a state.
862
- *
863
- * Or, a function with the signature `function(state, transition) { return matches; }`
864
- * which should return a boolean to indicate if a state matches.
865
- *
866
- * Or, `true` to always match
867
- */
868
- export type HookMatchCriterion = string | IStateMatch | boolean;
869
- declare enum TransitionHookPhase {
870
- CREATE = 0,
871
- BEFORE = 1,
872
- RUN = 2,
873
- SUCCESS = 3,
874
- ERROR = 4,
875
- }
876
- declare enum TransitionHookScope {
877
- TRANSITION = 0,
878
- STATE = 1,
879
- }
880
- export { TransitionHookPhase, TransitionHookScope };