@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,10 +1,10 @@
1
- import { StateDeclaration } from '../state/interface';
2
- import { PredicateBinary } from '../common/common';
3
- import { Transition } from './transition';
4
- import { StateObject } from '../state/stateObject';
5
- import { PathNode } from '../path/pathNode';
6
- import { TargetState } from '../state/targetState';
7
- import { RegisteredHook } from './hookRegistry';
1
+ import { StateDeclaration } from "../state/interface";
2
+ import { PredicateBinary } from "../common/common";
3
+ import { Transition } from "./transition";
4
+ import { StateObject } from "../state/stateObject";
5
+ import { PathNode } from "../path/pathNode";
6
+ import { TargetState } from "../state/targetState";
7
+ import { RegisteredHook } from "./hookRegistry";
8
8
  /**
9
9
  * The TransitionOptions object can be used to change the behavior of a transition.
10
10
  *
@@ -12,91 +12,91 @@ import { RegisteredHook } from './hookRegistry';
12
12
  * It can also be used with a `uiSref`.
13
13
  */
14
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';
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
91
  }
92
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;
93
+ current?: () => Transition;
94
+ transition?: Transition;
95
+ hookType?: string;
96
+ target?: any;
97
+ traceData?: any;
98
+ bind?: any;
99
+ stateHook?: boolean;
100
100
  }
101
101
  /**
102
102
  * TreeChanges encapsulates the various Paths that are involved in a Transition.
@@ -119,50 +119,54 @@ export interface TransitionHookOptions {
119
119
  * @todo show visual state tree
120
120
  */
121
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[];
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
164
  }
165
- export declare type IHookRegistration = (matchCriteria: HookMatchCriteria, callback: HookFn, options?: HookRegOptions) => Function;
165
+ export declare type IHookRegistration = (
166
+ matchCriteria: HookMatchCriteria,
167
+ callback: HookFn,
168
+ options?: HookRegOptions,
169
+ ) => Function;
166
170
  /**
167
171
  * The signature for Transition Hooks.
168
172
  *
@@ -187,7 +191,7 @@ export declare type IHookRegistration = (matchCriteria: HookMatchCriteria, callb
187
191
  *
188
192
  */
189
193
  export interface TransitionHookFn {
190
- (transition: Transition): HookResult;
194
+ (transition: Transition): HookResult;
191
195
  }
192
196
  /**
193
197
  * The signature for Transition State Hooks.
@@ -211,7 +215,7 @@ export interface TransitionHookFn {
211
215
  * @returns a [[HookResult]] which may alter the transition
212
216
  */
213
217
  export interface TransitionStateHookFn {
214
- (transition: Transition, state: StateDeclaration): HookResult;
218
+ (transition: Transition, state: StateDeclaration): HookResult;
215
219
  }
216
220
  /**
217
221
  * The signature for Transition onCreate Hooks.
@@ -223,9 +227,12 @@ export interface TransitionStateHookFn {
223
227
  * @return a [[Transition]] which will then be returned from [[TransitionService.create]]
224
228
  */
225
229
  export interface TransitionCreateHookFn {
226
- (transition: Transition): void;
230
+ (transition: Transition): void;
227
231
  }
228
- export declare type HookFn = TransitionHookFn | TransitionStateHookFn | TransitionCreateHookFn;
232
+ export declare type HookFn =
233
+ | TransitionHookFn
234
+ | TransitionStateHookFn
235
+ | TransitionCreateHookFn;
229
236
  /**
230
237
  * The return value of a [[TransitionHookFn]] or [[TransitionStateHookFn]]
231
238
  *
@@ -239,29 +246,33 @@ export declare type HookFn = TransitionHookFn | TransitionStateHookFn | Transiti
239
246
  * - If the promise resolves to anything else, the transition will resume
240
247
  * - Anything else: the transition will resume
241
248
  */
242
- export declare type HookResult = boolean | TargetState | void | Promise<boolean | TargetState | void>;
249
+ export declare type HookResult =
250
+ | boolean
251
+ | TargetState
252
+ | void
253
+ | Promise<boolean | TargetState | void>;
243
254
  /**
244
255
  * These options may be provided when registering a Transition Hook (such as `onStart`)
245
256
  */
246
257
  export interface HookRegOptions {
247
- /**
248
- * Sets the priority of the registered hook
249
- *
250
- * Hooks of the same type (onBefore, onStart, etc) are invoked in priority order. A hook with a higher priority
251
- * is invoked before a hook with a lower priority.
252
- *
253
- * The default hook priority is 0
254
- */
255
- priority?: number;
256
- /**
257
- * Specifies what `this` is bound to during hook invocation.
258
- */
259
- bind?: any;
260
- /**
261
- * Limits the number of times that the hook will be invoked.
262
- * Once the hook has been invoked this many times, it is automatically deregistered.
263
- */
264
- invokeLimit?: number;
258
+ /**
259
+ * Sets the priority of the registered hook
260
+ *
261
+ * Hooks of the same type (onBefore, onStart, etc) are invoked in priority order. A hook with a higher priority
262
+ * is invoked before a hook with a lower priority.
263
+ *
264
+ * The default hook priority is 0
265
+ */
266
+ priority?: number;
267
+ /**
268
+ * Specifies what `this` is bound to during hook invocation.
269
+ */
270
+ bind?: any;
271
+ /**
272
+ * Limits the number of times that the hook will be invoked.
273
+ * Once the hook has been invoked this many times, it is automatically deregistered.
274
+ */
275
+ invokeLimit?: number;
265
276
  }
266
277
  /**
267
278
  * This interface specifies the api for registering Transition Hooks. Both the
@@ -269,426 +280,458 @@ export interface HookRegOptions {
269
280
  * Note: the Transition object only allows hooks to be registered before the Transition is started.
270
281
  */
271
282
  export interface IHookRegistry {
272
- /** @internal place to store the hooks */
273
- _registeredHooks: {
274
- [key: string]: RegisteredHook[];
275
- };
276
- /**
277
- * Registers a [[TransitionHookFn]], called *before a transition starts*.
278
- *
279
- * Registers a transition lifecycle hook, which is invoked before a transition even begins.
280
- * This hook can be useful to implement logic which prevents a transition from even starting, such
281
- * as authentication, redirection
282
- *
283
- * See [[TransitionHookFn]] for the signature of the function.
284
- *
285
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
286
- * To match all Transitions, use an empty criteria object `{}`.
287
- *
288
- * ### Lifecycle
289
- *
290
- * `onBefore` hooks are invoked *before a Transition starts*.
291
- * No resolves have been fetched yet.
292
- * Each `onBefore` hook is invoked synchronously, in the same call stack as [[StateService.transitionTo]].
293
- * The registered `onBefore` hooks are invoked in priority order.
294
- *
295
- * Note: during the `onBefore` phase, additional hooks can be added to the specific [[Transition]] instance.
296
- * These "on-the-fly" hooks only affect the currently running transition..
297
- *
298
- * ### Return value
299
- *
300
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
301
- * See [[HookResult]] for more information.
302
- *
303
- * If any hook modifies the transition *synchronously* (by throwing, returning `false`, or returning
304
- * a [[TargetState]]), the remainder of the hooks are skipped.
305
- * If a hook returns a promise, the remainder of the `onBefore` hooks are still invoked synchronously.
306
- * All promises are resolved, and processed asynchronously before the `onStart` phase of the Transition.
307
- *
308
- * ### Examples
309
- *
310
- * #### Default Substate
311
- *
312
- * This example redirects any transition from 'home' to 'home.dashboard'. This is commonly referred to as a
313
- * "default substate".
314
- *
315
- * @example
316
- * ```js
317
- * // ng2
318
- * transitionService.onBefore({ to: 'home' }, (trans: Transition) =>
319
- * trans.router.stateService.target("home.dashboard"));
320
- * ```
321
- *
322
- * #### Data Driven Default Substate
323
- *
324
- * This example provides data-driven default substate functionality. It matches on a transition to any state
325
- * which has `defaultSubstate: "some.sub.state"` defined. See: [[Transition.to]] which returns the "to state"
326
- * definition.
327
- *
328
- * @example
329
- * ```js
330
- * // ng1
331
- * // state declaration
332
- * {
333
- * name: 'home',
334
- * template: '<div ui-view/>',
335
- * defaultSubstate: 'home.dashboard'
336
- * }
337
- *
338
- * var criteria = {
339
- * to: function(state) {
340
- * return state.defaultSubstate != null;
341
- * }
342
- * }
343
- *
344
- * $transitions.onBefore(criteria, function(trans: Transition) {
345
- * var substate = trans.to().defaultSubstate;
346
- * return trans.router.stateService.target(substate);
347
- * });
348
- * ```
349
- *
350
- *
351
- * #### Require authentication
352
- *
353
- * This example cancels a transition to a state which requires authentication, if the user is not currently authenticated.
354
- *
355
- * This example assumes a state tree where all states which require authentication are children of a parent `'requireauth'` state.
356
- * This example assumes `MyAuthService` synchronously returns a boolean from `isAuthenticated()`.
357
- *
358
- * #### Example:
359
- * ```js
360
- * // ng1
361
- * $transitions.onBefore( { to: 'requireauth.**' }, function(trans) {
362
- * var myAuthService = trans.injector().get('MyAuthService');
363
- * // If isAuthenticated returns false, the transition is cancelled.
364
- * return myAuthService.isAuthenticated();
365
- * });
366
- * ```
367
- *
368
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
369
- * @param callback the hook function which will be invoked.
370
- * @returns a function which deregisters the hook.
371
- */
372
- onBefore(matchCriteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
373
- /**
374
- * Registers a [[TransitionHookFn]], called when a transition starts.
375
- *
376
- * Registers a transition lifecycle hook, which is invoked as a transition starts running.
377
- * This hook can be useful to perform some asynchronous action before completing a transition.
378
- *
379
- * See [[TransitionHookFn]] for the signature of the function.
380
- *
381
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
382
- * To match all Transitions, use an empty criteria object `{}`.
383
- *
384
- * ### Lifecycle
385
- *
386
- * `onStart` hooks are invoked asynchronously when the Transition starts running.
387
- * This happens after the `onBefore` phase is complete.
388
- * At this point, the Transition has not yet exited nor entered any states.
389
- * The registered `onStart` hooks are invoked in priority order.
390
- *
391
- * Note: A built-in `onStart` hook with high priority is used to fetch any eager resolve data.
392
- *
393
- * ### Return value
394
- *
395
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
396
- * See [[HookResult]] for more information.
397
- *
398
- * ### Example
399
- *
400
- * #### Login during transition
401
- *
402
- * This example intercepts any transition to a state which requires authentication, when the user is
403
- * not currently authenticated. It allows the user to authenticate asynchronously, then resumes the
404
- * transition. If the user did not authenticate successfully, it redirects to the "guest" state, which
405
- * does not require authentication.
406
- *
407
- * This example assumes:
408
- * - a state tree where all states which require authentication are children of a parent `'auth'` state.
409
- * - `MyAuthService.isAuthenticated()` synchronously returns a boolean.
410
- * - `MyAuthService.authenticate()` presents a login dialog, and returns a promise which is resolved
411
- * or rejected, whether or not the login attempt was successful.
412
- *
413
- * #### Example:
414
- * ```js
415
- * // ng1
416
- * $transitions.onStart( { to: 'auth.**' }, function(trans) {
417
- * var $state = trans.router.stateService;
418
- * var MyAuthService = trans.injector().get('MyAuthService');
419
- *
420
- * // If the user is not authenticated
421
- * if (!MyAuthService.isAuthenticated()) {
422
- *
423
- * // Then return a promise for a successful login.
424
- * // The transition will wait for this promise to settle
425
- *
426
- * return MyAuthService.authenticate().catch(function() {
427
- *
428
- * // If the authenticate() method failed for whatever reason,
429
- * // redirect to a 'guest' state which doesn't require auth.
430
- * return $state.target("guest");
431
- * });
432
- * }
433
- * });
434
- * ```
435
- *
436
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
437
- * @param callback the hook function which will be injected and invoked.
438
- * @returns a function which deregisters the hook.
439
- */
440
- onStart(matchCriteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
441
- /**
442
- * Registers a [[TransitionStateHookFn]], called when a specific state is entered.
443
- *
444
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being entered.
445
- *
446
- * Since this hook is run only when the specific state is being *entered*, it can be useful for
447
- * performing tasks when entering a submodule/feature area such as initializing a stateful service,
448
- * or for guarding access to a submodule/feature area.
449
- *
450
- * See [[TransitionStateHookFn]] for the signature of the function.
451
- *
452
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
453
- * `onEnter` hooks generally specify `{ entering: 'somestate' }`.
454
- * To match all Transitions, use an empty criteria object `{}`.
455
- *
456
- * ### Lifecycle
457
- *
458
- * `onEnter` hooks are invoked when the Transition is entering a state.
459
- * States are entered after the `onRetain` phase is complete.
460
- * If more than one state is being entered, the parent state is entered first.
461
- * The registered `onEnter` hooks for a state are invoked in priority order.
462
- *
463
- * Note: A built-in `onEnter` hook with high priority is used to fetch lazy resolve data for states being entered.
464
- *
465
- * ### Return value
466
- *
467
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
468
- * See [[HookResult]] for more information.
469
- *
470
- * ### Inside a state declaration
471
- *
472
- * Instead of registering `onEnter` hooks using the [[TransitionService]], you may define an `onEnter` hook
473
- * directly on a state declaration (see: [[StateDeclaration.onEnter]]).
474
- *
475
- *
476
- * ### Examples
477
- *
478
- * #### Audit Log
479
- *
480
- * This example uses a service to log that a user has entered the admin section of an app.
481
- * This assumes that there are substates of the "admin" state, such as "admin.users", "admin.pages", etc.
482
- * @example
483
- * ```
484
- *
485
- * $transitions.onEnter({ entering: 'admin' }, function(transition, state) {
486
- * var AuditService = trans.injector().get('AuditService');
487
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
488
- * }
489
- * ```
490
- *
491
- * #### Audit Log (inside a state declaration)
492
- *
493
- * The `onEnter` inside this state declaration is syntactic sugar for the previous Audit Log example.
494
- * ```
495
- * {
496
- * name: 'admin',
497
- * component: 'admin',
498
- * onEnter: function($transition$, $state$) {
499
- * var AuditService = $transition$.injector().get('AuditService');
500
- * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
501
- * }
502
- * }
503
- * ```
504
- *
505
- * Note: A state declaration's `onEnter` function is injected for Angular 1 only.
506
- *
507
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
508
- * @param callback the hook function which will be injected and invoked.
509
- * @returns a function which deregisters the hook.
510
- */
511
- onEnter(matchCriteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
512
- /**
513
- * Registers a [[TransitionStateHookFn]], called when a specific state is retained/kept.
514
- *
515
- * Registers a lifecycle hook, which is invoked (during a transition) for
516
- * a specific state that was previously active will remain active (is not being entered nor exited).
517
- *
518
- * This hook is invoked when a state is "retained" or "kept".
519
- * It means the transition is coming *from* a substate of the retained state *to* a substate of the retained state.
520
- * This hook can be used to perform actions when the user moves from one substate to another, such as between steps in a wizard.
521
- *
522
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
523
- * `onRetain` hooks generally specify `{ retained: 'somestate' }`.
524
- * To match all Transitions, use an empty criteria object `{}`.
525
- *
526
- * ### Lifecycle
527
- *
528
- * `onRetain` hooks are invoked after any `onExit` hooks have been fired.
529
- * If more than one state is retained, the child states' `onRetain` hooks are invoked first.
530
- * The registered `onRetain` hooks for a state are invoked in priority order.
531
- *
532
- * ### Return value
533
- *
534
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
535
- * See [[HookResult]] for more information.
536
- *
537
- * ### Inside a state declaration
538
- *
539
- * Instead of registering `onRetain` hooks using the [[TransitionService]], you may define an `onRetain` hook
540
- * directly on a state declaration (see: [[StateDeclaration.onRetain]]).
541
- *
542
- * Note: A state declaration's `onRetain` 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
- onRetain(matchCriteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
549
- /**
550
- * Registers a [[TransitionStateHookFn]], called when a specific state is exited.
551
- *
552
- * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being exited.
553
- *
554
- * Since this hook is run only when the specific state is being *exited*, it can be useful for
555
- * performing tasks when leaving a submodule/feature area such as cleaning up a stateful service,
556
- * or for preventing the user from leaving a state or submodule until some criteria is satisfied.
557
- *
558
- * See [[TransitionStateHookFn]] for the signature of the function.
559
- *
560
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
561
- * `onExit` hooks generally specify `{ exiting: 'somestate' }`.
562
- * To match all Transitions, use an empty criteria object `{}`.
563
- *
564
- * ### Lifecycle
565
- *
566
- * `onExit` hooks are invoked when the Transition is exiting a state.
567
- * States are exited after any `onStart` phase is complete.
568
- * If more than one state is being exited, the child states are exited first.
569
- * The registered `onExit` hooks for a state are invoked in priority order.
570
- *
571
- * ### Return value
572
- *
573
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
574
- * See [[HookResult]] for more information.
575
- *
576
- * ### Inside a state declaration
577
- *
578
- * Instead of registering `onExit` hooks using the [[TransitionService]], you may define an `onExit` hook
579
- * directly on a state declaration (see: [[StateDeclaration.onExit]]).
580
- *
581
- * Note: A state declaration's `onExit` function is injected for Angular 1 only.
582
- *
583
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
584
- * @param callback the hook function which will be injected and invoked.
585
- * @returns a function which deregisters the hook.
586
- */
587
- onExit(matchCriteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
588
- /**
589
- * Registers a [[TransitionHookFn]], called *just before a transition finishes*.
590
- *
591
- * Registers a transition lifecycle hook, which is invoked just before a transition finishes.
592
- * This hook is a last chance to cancel or redirect a transition.
593
- *
594
- * See [[TransitionHookFn]] for the signature of the function.
595
- *
596
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
597
- * To match all Transitions, use an empty criteria object `{}`.
598
- *
599
- * ### Lifecycle
600
- *
601
- * `onFinish` hooks are invoked after the `onEnter` phase is complete.
602
- * These hooks are invoked just before the transition is "committed".
603
- * Each hook is invoked in priority order.
604
- *
605
- * ### Return value
606
- *
607
- * The hook's return value can be used to pause, cancel, or redirect the current Transition.
608
- * See [[HookResult]] for more information.
609
- *
610
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
611
- * @param callback the hook function which will be injected and invoked.
612
- * @returns a function which deregisters the hook.
613
- */
614
- onFinish(matchCriteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
615
- /**
616
- * Registers a [[TransitionHookFn]], called after a successful transition completed.
617
- *
618
- * Registers a transition lifecycle hook, which is invoked after a transition successfully completes.
619
- *
620
- * See [[TransitionHookFn]] for the signature of the function.
621
- *
622
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
623
- * To match all Transitions, use an empty criteria object `{}`.
624
- *
625
- * ### Lifecycle
626
- *
627
- * `onSuccess` hooks are chained off the Transition's promise (see [[Transition.promise]]).
628
- * If the Transition is successful and its promise is resolved, then the `onSuccess` hooks are invoked.
629
- * Since these hooks are run after the transition is over, their return value is ignored.
630
- * The `onSuccess` hooks are invoked in priority order.
631
- *
632
- * ### Return value
633
- *
634
- * Since the Transition is already completed, the hook's return value is ignored
635
- *
636
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
637
- * @param callback the hook function which will be injected and invoked.
638
- * @returns a function which deregisters the hook.
639
- */
640
- onSuccess(matchCriteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
641
- /**
642
- * Registers a [[TransitionHookFn]], called after a transition has errored.
643
- *
644
- * Registers a transition lifecycle hook, which is invoked after a transition has been rejected for any reason.
645
- *
646
- * See [[TransitionHookFn]] for the signature of the function.
647
- *
648
- * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
649
- * To match all Transitions, use an empty criteria object `{}`.
650
- *
651
- * ### Lifecycle
652
- *
653
- * The `onError` hooks are chained off the Transition's promise (see [[Transition.promise]]).
654
- * If a Transition fails, its promise is rejected and the `onError` hooks are invoked.
655
- * The `onError` hooks are invoked in priority order.
656
- *
657
- * Since these hooks are run after the transition is over, their return value is ignored.
658
- *
659
- * A transition "errors" if it was started, but failed to complete (for any reason).
660
- * A *non-exhaustive list* of reasons a transition can error:
661
- *
662
- * - A transition was cancelled because a new transition started while it was still running (`Transition superseded`)
663
- * - A transition was cancelled by a Transition Hook returning false
664
- * - A transition was redirected by a Transition Hook returning a [[TargetState]]
665
- * - A Transition Hook or resolve function threw an error
666
- * - A Transition Hook returned a rejected promise
667
- * - A resolve function returned a rejected promise
668
- *
669
- * To check the failure reason, inspect the return value of [[Transition.error]].
670
- *
671
- * Note: `onError` should be used for targeted error handling, or error recovery.
672
- * For simple catch-all error reporting, use [[StateService.defaultErrorHandler]].
673
- *
674
- * ### Return value
675
- *
676
- * Since the Transition is already completed, the hook's return value is ignored
677
- *
678
- * @param matchCriteria defines which Transitions the Hook should be invoked for.
679
- * @param callback the hook function which will be injected and invoked.
680
- * @returns a function which deregisters the hook.
681
- */
682
- onError(matchCriteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
683
- /**
684
- * Returns all the registered hooks of a given `hookName` type
685
- *
686
- * #### Example:
687
- * ```
688
- * $transitions.getHooks("onEnter")
689
- * ```
690
- */
691
- getHooks(hookName: string): RegisteredHook[];
283
+ /** @internal place to store the hooks */
284
+ _registeredHooks: {
285
+ [key: string]: RegisteredHook[];
286
+ };
287
+ /**
288
+ * Registers a [[TransitionHookFn]], called *before a transition starts*.
289
+ *
290
+ * Registers a transition lifecycle hook, which is invoked before a transition even begins.
291
+ * This hook can be useful to implement logic which prevents a transition from even starting, such
292
+ * as authentication, redirection
293
+ *
294
+ * See [[TransitionHookFn]] for the signature of the function.
295
+ *
296
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
297
+ * To match all Transitions, use an empty criteria object `{}`.
298
+ *
299
+ * ### Lifecycle
300
+ *
301
+ * `onBefore` hooks are invoked *before a Transition starts*.
302
+ * No resolves have been fetched yet.
303
+ * Each `onBefore` hook is invoked synchronously, in the same call stack as [[StateService.transitionTo]].
304
+ * The registered `onBefore` hooks are invoked in priority order.
305
+ *
306
+ * Note: during the `onBefore` phase, additional hooks can be added to the specific [[Transition]] instance.
307
+ * These "on-the-fly" hooks only affect the currently running transition..
308
+ *
309
+ * ### Return value
310
+ *
311
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
312
+ * See [[HookResult]] for more information.
313
+ *
314
+ * If any hook modifies the transition *synchronously* (by throwing, returning `false`, or returning
315
+ * a [[TargetState]]), the remainder of the hooks are skipped.
316
+ * If a hook returns a promise, the remainder of the `onBefore` hooks are still invoked synchronously.
317
+ * All promises are resolved, and processed asynchronously before the `onStart` phase of the Transition.
318
+ *
319
+ * ### Examples
320
+ *
321
+ * #### Default Substate
322
+ *
323
+ * This example redirects any transition from 'home' to 'home.dashboard'. This is commonly referred to as a
324
+ * "default substate".
325
+ *
326
+ * @example
327
+ * ```js
328
+ * // ng2
329
+ * transitionService.onBefore({ to: 'home' }, (trans: Transition) =>
330
+ * trans.router.stateService.target("home.dashboard"));
331
+ * ```
332
+ *
333
+ * #### Data Driven Default Substate
334
+ *
335
+ * This example provides data-driven default substate functionality. It matches on a transition to any state
336
+ * which has `defaultSubstate: "some.sub.state"` defined. See: [[Transition.to]] which returns the "to state"
337
+ * definition.
338
+ *
339
+ * @example
340
+ * ```js
341
+ * // ng1
342
+ * // state declaration
343
+ * {
344
+ * name: 'home',
345
+ * template: '<div ui-view/>',
346
+ * defaultSubstate: 'home.dashboard'
347
+ * }
348
+ *
349
+ * var criteria = {
350
+ * to: function(state) {
351
+ * return state.defaultSubstate != null;
352
+ * }
353
+ * }
354
+ *
355
+ * $transitions.onBefore(criteria, function(trans: Transition) {
356
+ * var substate = trans.to().defaultSubstate;
357
+ * return trans.router.stateService.target(substate);
358
+ * });
359
+ * ```
360
+ *
361
+ *
362
+ * #### Require authentication
363
+ *
364
+ * This example cancels a transition to a state which requires authentication, if the user is not currently authenticated.
365
+ *
366
+ * This example assumes a state tree where all states which require authentication are children of a parent `'requireauth'` state.
367
+ * This example assumes `MyAuthService` synchronously returns a boolean from `isAuthenticated()`.
368
+ *
369
+ * #### Example:
370
+ * ```js
371
+ * // ng1
372
+ * $transitions.onBefore( { to: 'requireauth.**' }, function(trans) {
373
+ * var myAuthService = trans.injector().get('MyAuthService');
374
+ * // If isAuthenticated returns false, the transition is cancelled.
375
+ * return myAuthService.isAuthenticated();
376
+ * });
377
+ * ```
378
+ *
379
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
380
+ * @param callback the hook function which will be invoked.
381
+ * @returns a function which deregisters the hook.
382
+ */
383
+ onBefore(
384
+ matchCriteria: HookMatchCriteria,
385
+ callback: TransitionHookFn,
386
+ options?: HookRegOptions,
387
+ ): Function;
388
+ /**
389
+ * Registers a [[TransitionHookFn]], called when a transition starts.
390
+ *
391
+ * Registers a transition lifecycle hook, which is invoked as a transition starts running.
392
+ * This hook can be useful to perform some asynchronous action before completing a transition.
393
+ *
394
+ * See [[TransitionHookFn]] for the signature of the function.
395
+ *
396
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
397
+ * To match all Transitions, use an empty criteria object `{}`.
398
+ *
399
+ * ### Lifecycle
400
+ *
401
+ * `onStart` hooks are invoked asynchronously when the Transition starts running.
402
+ * This happens after the `onBefore` phase is complete.
403
+ * At this point, the Transition has not yet exited nor entered any states.
404
+ * The registered `onStart` hooks are invoked in priority order.
405
+ *
406
+ * Note: A built-in `onStart` hook with high priority is used to fetch any eager resolve data.
407
+ *
408
+ * ### Return value
409
+ *
410
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
411
+ * See [[HookResult]] for more information.
412
+ *
413
+ * ### Example
414
+ *
415
+ * #### Login during transition
416
+ *
417
+ * This example intercepts any transition to a state which requires authentication, when the user is
418
+ * not currently authenticated. It allows the user to authenticate asynchronously, then resumes the
419
+ * transition. If the user did not authenticate successfully, it redirects to the "guest" state, which
420
+ * does not require authentication.
421
+ *
422
+ * This example assumes:
423
+ * - a state tree where all states which require authentication are children of a parent `'auth'` state.
424
+ * - `MyAuthService.isAuthenticated()` synchronously returns a boolean.
425
+ * - `MyAuthService.authenticate()` presents a login dialog, and returns a promise which is resolved
426
+ * or rejected, whether or not the login attempt was successful.
427
+ *
428
+ * #### Example:
429
+ * ```js
430
+ * // ng1
431
+ * $transitions.onStart( { to: 'auth.**' }, function(trans) {
432
+ * var $state = trans.router.stateService;
433
+ * var MyAuthService = trans.injector().get('MyAuthService');
434
+ *
435
+ * // If the user is not authenticated
436
+ * if (!MyAuthService.isAuthenticated()) {
437
+ *
438
+ * // Then return a promise for a successful login.
439
+ * // The transition will wait for this promise to settle
440
+ *
441
+ * return MyAuthService.authenticate().catch(function() {
442
+ *
443
+ * // If the authenticate() method failed for whatever reason,
444
+ * // redirect to a 'guest' state which doesn't require auth.
445
+ * return $state.target("guest");
446
+ * });
447
+ * }
448
+ * });
449
+ * ```
450
+ *
451
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
452
+ * @param callback the hook function which will be injected and invoked.
453
+ * @returns a function which deregisters the hook.
454
+ */
455
+ onStart(
456
+ matchCriteria: HookMatchCriteria,
457
+ callback: TransitionHookFn,
458
+ options?: HookRegOptions,
459
+ ): Function;
460
+ /**
461
+ * Registers a [[TransitionStateHookFn]], called when a specific state is entered.
462
+ *
463
+ * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being entered.
464
+ *
465
+ * Since this hook is run only when the specific state is being *entered*, it can be useful for
466
+ * performing tasks when entering a submodule/feature area such as initializing a stateful service,
467
+ * or for guarding access to a submodule/feature area.
468
+ *
469
+ * See [[TransitionStateHookFn]] for the signature of the function.
470
+ *
471
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
472
+ * `onEnter` hooks generally specify `{ entering: 'somestate' }`.
473
+ * To match all Transitions, use an empty criteria object `{}`.
474
+ *
475
+ * ### Lifecycle
476
+ *
477
+ * `onEnter` hooks are invoked when the Transition is entering a state.
478
+ * States are entered after the `onRetain` phase is complete.
479
+ * If more than one state is being entered, the parent state is entered first.
480
+ * The registered `onEnter` hooks for a state are invoked in priority order.
481
+ *
482
+ * Note: A built-in `onEnter` hook with high priority is used to fetch lazy resolve data for states being entered.
483
+ *
484
+ * ### Return value
485
+ *
486
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
487
+ * See [[HookResult]] for more information.
488
+ *
489
+ * ### Inside a state declaration
490
+ *
491
+ * Instead of registering `onEnter` hooks using the [[TransitionService]], you may define an `onEnter` hook
492
+ * directly on a state declaration (see: [[StateDeclaration.onEnter]]).
493
+ *
494
+ *
495
+ * ### Examples
496
+ *
497
+ * #### Audit Log
498
+ *
499
+ * This example uses a service to log that a user has entered the admin section of an app.
500
+ * This assumes that there are substates of the "admin" state, such as "admin.users", "admin.pages", etc.
501
+ * @example
502
+ * ```
503
+ *
504
+ * $transitions.onEnter({ entering: 'admin' }, function(transition, state) {
505
+ * var AuditService = trans.injector().get('AuditService');
506
+ * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
507
+ * }
508
+ * ```
509
+ *
510
+ * #### Audit Log (inside a state declaration)
511
+ *
512
+ * The `onEnter` inside this state declaration is syntactic sugar for the previous Audit Log example.
513
+ * ```
514
+ * {
515
+ * name: 'admin',
516
+ * component: 'admin',
517
+ * onEnter: function($transition$, $state$) {
518
+ * var AuditService = $transition$.injector().get('AuditService');
519
+ * AuditService.log("Entered " + state.name + " module while transitioning to " + transition.to().name);
520
+ * }
521
+ * }
522
+ * ```
523
+ *
524
+ * Note: A state declaration's `onEnter` function is injected for Angular 1 only.
525
+ *
526
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
527
+ * @param callback the hook function which will be injected and invoked.
528
+ * @returns a function which deregisters the hook.
529
+ */
530
+ onEnter(
531
+ matchCriteria: HookMatchCriteria,
532
+ callback: TransitionStateHookFn,
533
+ options?: HookRegOptions,
534
+ ): Function;
535
+ /**
536
+ * Registers a [[TransitionStateHookFn]], called when a specific state is retained/kept.
537
+ *
538
+ * Registers a lifecycle hook, which is invoked (during a transition) for
539
+ * a specific state that was previously active will remain active (is not being entered nor exited).
540
+ *
541
+ * This hook is invoked when a state is "retained" or "kept".
542
+ * It means the transition is coming *from* a substate of the retained state *to* a substate of the retained state.
543
+ * This hook can be used to perform actions when the user moves from one substate to another, such as between steps in a wizard.
544
+ *
545
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
546
+ * `onRetain` hooks generally specify `{ retained: 'somestate' }`.
547
+ * To match all Transitions, use an empty criteria object `{}`.
548
+ *
549
+ * ### Lifecycle
550
+ *
551
+ * `onRetain` hooks are invoked after any `onExit` hooks have been fired.
552
+ * If more than one state is retained, the child states' `onRetain` hooks are invoked first.
553
+ * The registered `onRetain` hooks for a state are invoked in priority order.
554
+ *
555
+ * ### Return value
556
+ *
557
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
558
+ * See [[HookResult]] for more information.
559
+ *
560
+ * ### Inside a state declaration
561
+ *
562
+ * Instead of registering `onRetain` hooks using the [[TransitionService]], you may define an `onRetain` hook
563
+ * directly on a state declaration (see: [[StateDeclaration.onRetain]]).
564
+ *
565
+ * Note: A state declaration's `onRetain` function is injected for Angular 1 only.
566
+ *
567
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
568
+ * @param callback the hook function which will be injected and invoked.
569
+ * @returns a function which deregisters the hook.
570
+ */
571
+ onRetain(
572
+ matchCriteria: HookMatchCriteria,
573
+ callback: TransitionStateHookFn,
574
+ options?: HookRegOptions,
575
+ ): Function;
576
+ /**
577
+ * Registers a [[TransitionStateHookFn]], called when a specific state is exited.
578
+ *
579
+ * Registers a lifecycle hook, which is invoked (during a transition) when a specific state is being exited.
580
+ *
581
+ * Since this hook is run only when the specific state is being *exited*, it can be useful for
582
+ * performing tasks when leaving a submodule/feature area such as cleaning up a stateful service,
583
+ * or for preventing the user from leaving a state or submodule until some criteria is satisfied.
584
+ *
585
+ * See [[TransitionStateHookFn]] for the signature of the function.
586
+ *
587
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
588
+ * `onExit` hooks generally specify `{ exiting: 'somestate' }`.
589
+ * To match all Transitions, use an empty criteria object `{}`.
590
+ *
591
+ * ### Lifecycle
592
+ *
593
+ * `onExit` hooks are invoked when the Transition is exiting a state.
594
+ * States are exited after any `onStart` phase is complete.
595
+ * If more than one state is being exited, the child states are exited first.
596
+ * The registered `onExit` hooks for a state are invoked in priority order.
597
+ *
598
+ * ### Return value
599
+ *
600
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
601
+ * See [[HookResult]] for more information.
602
+ *
603
+ * ### Inside a state declaration
604
+ *
605
+ * Instead of registering `onExit` hooks using the [[TransitionService]], you may define an `onExit` hook
606
+ * directly on a state declaration (see: [[StateDeclaration.onExit]]).
607
+ *
608
+ * Note: A state declaration's `onExit` function is injected for Angular 1 only.
609
+ *
610
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
611
+ * @param callback the hook function which will be injected and invoked.
612
+ * @returns a function which deregisters the hook.
613
+ */
614
+ onExit(
615
+ matchCriteria: HookMatchCriteria,
616
+ callback: TransitionStateHookFn,
617
+ options?: HookRegOptions,
618
+ ): Function;
619
+ /**
620
+ * Registers a [[TransitionHookFn]], called *just before a transition finishes*.
621
+ *
622
+ * Registers a transition lifecycle hook, which is invoked just before a transition finishes.
623
+ * This hook is a last chance to cancel or redirect a transition.
624
+ *
625
+ * See [[TransitionHookFn]] for the signature of the function.
626
+ *
627
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
628
+ * To match all Transitions, use an empty criteria object `{}`.
629
+ *
630
+ * ### Lifecycle
631
+ *
632
+ * `onFinish` hooks are invoked after the `onEnter` phase is complete.
633
+ * These hooks are invoked just before the transition is "committed".
634
+ * Each hook is invoked in priority order.
635
+ *
636
+ * ### Return value
637
+ *
638
+ * The hook's return value can be used to pause, cancel, or redirect the current Transition.
639
+ * See [[HookResult]] for more information.
640
+ *
641
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
642
+ * @param callback the hook function which will be injected and invoked.
643
+ * @returns a function which deregisters the hook.
644
+ */
645
+ onFinish(
646
+ matchCriteria: HookMatchCriteria,
647
+ callback: TransitionHookFn,
648
+ options?: HookRegOptions,
649
+ ): Function;
650
+ /**
651
+ * Registers a [[TransitionHookFn]], called after a successful transition completed.
652
+ *
653
+ * Registers a transition lifecycle hook, which is invoked after a transition successfully completes.
654
+ *
655
+ * See [[TransitionHookFn]] for the signature of the function.
656
+ *
657
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
658
+ * To match all Transitions, use an empty criteria object `{}`.
659
+ *
660
+ * ### Lifecycle
661
+ *
662
+ * `onSuccess` hooks are chained off the Transition's promise (see [[Transition.promise]]).
663
+ * If the Transition is successful and its promise is resolved, then the `onSuccess` hooks are invoked.
664
+ * Since these hooks are run after the transition is over, their return value is ignored.
665
+ * The `onSuccess` hooks are invoked in priority order.
666
+ *
667
+ * ### Return value
668
+ *
669
+ * Since the Transition is already completed, the hook's return value is ignored
670
+ *
671
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
672
+ * @param callback the hook function which will be injected and invoked.
673
+ * @returns a function which deregisters the hook.
674
+ */
675
+ onSuccess(
676
+ matchCriteria: HookMatchCriteria,
677
+ callback: TransitionHookFn,
678
+ options?: HookRegOptions,
679
+ ): Function;
680
+ /**
681
+ * Registers a [[TransitionHookFn]], called after a transition has errored.
682
+ *
683
+ * Registers a transition lifecycle hook, which is invoked after a transition has been rejected for any reason.
684
+ *
685
+ * See [[TransitionHookFn]] for the signature of the function.
686
+ *
687
+ * The [[HookMatchCriteria]] is used to determine which Transitions the hook should be invoked for.
688
+ * To match all Transitions, use an empty criteria object `{}`.
689
+ *
690
+ * ### Lifecycle
691
+ *
692
+ * The `onError` hooks are chained off the Transition's promise (see [[Transition.promise]]).
693
+ * If a Transition fails, its promise is rejected and the `onError` hooks are invoked.
694
+ * The `onError` hooks are invoked in priority order.
695
+ *
696
+ * Since these hooks are run after the transition is over, their return value is ignored.
697
+ *
698
+ * A transition "errors" if it was started, but failed to complete (for any reason).
699
+ * A *non-exhaustive list* of reasons a transition can error:
700
+ *
701
+ * - A transition was cancelled because a new transition started while it was still running (`Transition superseded`)
702
+ * - A transition was cancelled by a Transition Hook returning false
703
+ * - A transition was redirected by a Transition Hook returning a [[TargetState]]
704
+ * - A Transition Hook or resolve function threw an error
705
+ * - A Transition Hook returned a rejected promise
706
+ * - A resolve function returned a rejected promise
707
+ *
708
+ * To check the failure reason, inspect the return value of [[Transition.error]].
709
+ *
710
+ * Note: `onError` should be used for targeted error handling, or error recovery.
711
+ * For simple catch-all error reporting, use [[StateService.defaultErrorHandler]].
712
+ *
713
+ * ### Return value
714
+ *
715
+ * Since the Transition is already completed, the hook's return value is ignored
716
+ *
717
+ * @param matchCriteria defines which Transitions the Hook should be invoked for.
718
+ * @param callback the hook function which will be injected and invoked.
719
+ * @returns a function which deregisters the hook.
720
+ */
721
+ onError(
722
+ matchCriteria: HookMatchCriteria,
723
+ callback: TransitionHookFn,
724
+ options?: HookRegOptions,
725
+ ): Function;
726
+ /**
727
+ * Returns all the registered hooks of a given `hookName` type
728
+ *
729
+ * #### Example:
730
+ * ```
731
+ * $transitions.getHooks("onEnter")
732
+ * ```
733
+ */
734
+ getHooks(hookName: string): RegisteredHook[];
692
735
  }
693
736
  /** A predicate type which tests if a [[StateObject]] and [[Transition]] passes some test. Returns a boolean. */
694
737
  export declare type IStateMatch = PredicateBinary<StateObject, Transition>;
@@ -756,43 +799,43 @@ export declare type IStateMatch = PredicateBinary<StateObject, Transition>;
756
799
  * ```
757
800
  */
758
801
  export interface HookMatchCriteria {
759
- [key: string]: HookMatchCriterion | undefined;
760
- /** A [[HookMatchCriterion]] to match the destination state */
761
- to?: HookMatchCriterion;
762
- /** A [[HookMatchCriterion]] to match the original (from) state */
763
- from?: HookMatchCriterion;
764
- /** A [[HookMatchCriterion]] to match any state that would be exiting */
765
- exiting?: HookMatchCriterion;
766
- /** A [[HookMatchCriterion]] to match any state that would be retained */
767
- retained?: HookMatchCriterion;
768
- /** A [[HookMatchCriterion]] to match any state that would be entering */
769
- entering?: HookMatchCriterion;
802
+ [key: string]: HookMatchCriterion | undefined;
803
+ /** A [[HookMatchCriterion]] to match the destination state */
804
+ to?: HookMatchCriterion;
805
+ /** A [[HookMatchCriterion]] to match the original (from) state */
806
+ from?: HookMatchCriterion;
807
+ /** A [[HookMatchCriterion]] to match any state that would be exiting */
808
+ exiting?: HookMatchCriterion;
809
+ /** A [[HookMatchCriterion]] to match any state that would be retained */
810
+ retained?: HookMatchCriterion;
811
+ /** A [[HookMatchCriterion]] to match any state that would be entering */
812
+ entering?: HookMatchCriterion;
770
813
  }
771
814
  export interface IMatchingNodes {
772
- [key: string]: PathNode[];
773
- to: PathNode[];
774
- from: PathNode[];
775
- exiting: PathNode[];
776
- retained: PathNode[];
777
- entering: PathNode[];
815
+ [key: string]: PathNode[];
816
+ to: PathNode[];
817
+ from: PathNode[];
818
+ exiting: PathNode[];
819
+ retained: PathNode[];
820
+ entering: PathNode[];
778
821
  }
779
822
  /** @internal */
780
823
  export interface RegisteredHooks {
781
- [key: string]: RegisteredHook[];
824
+ [key: string]: RegisteredHook[];
782
825
  }
783
826
  /** @internal */
784
827
  export interface PathTypes {
785
- [key: string]: PathType;
786
- to: PathType;
787
- from: PathType;
788
- exiting: PathType;
789
- retained: PathType;
790
- entering: PathType;
828
+ [key: string]: PathType;
829
+ to: PathType;
830
+ from: PathType;
831
+ exiting: PathType;
832
+ retained: PathType;
833
+ entering: PathType;
791
834
  }
792
835
  /** @internal */
793
836
  export interface PathType {
794
- name: string;
795
- scope: TransitionHookScope;
837
+ name: string;
838
+ scope: TransitionHookScope;
796
839
  }
797
840
  /**
798
841
  * Hook Criterion used to match a transition.
@@ -806,14 +849,14 @@ export interface PathType {
806
849
  */
807
850
  export declare type HookMatchCriterion = string | IStateMatch | boolean;
808
851
  declare enum TransitionHookPhase {
809
- CREATE = 0,
810
- BEFORE = 1,
811
- RUN = 2,
812
- SUCCESS = 3,
813
- ERROR = 4
852
+ CREATE = 0,
853
+ BEFORE = 1,
854
+ RUN = 2,
855
+ SUCCESS = 3,
856
+ ERROR = 4,
814
857
  }
815
858
  declare enum TransitionHookScope {
816
- TRANSITION = 0,
817
- STATE = 1
859
+ TRANSITION = 0,
860
+ STATE = 1,
818
861
  }
819
862
  export { TransitionHookPhase, TransitionHookScope };