@@ -10,26 +10,55 @@ import { StateDeclaration, _ViewDeclaration, IInjectable, Transition, HookResult
10
10
*
11
11
* State hooks are registered as onEnter/onRetain/onExit in state declarations.
12
12
* State hooks can additionally be injected with $transition$ and $state$ for
13
- * the current [[Transition]] and [[State ]] in the transition.
13
+ * the current [[Transition]] and [[StateObject ]] in the transition.
14
14
*
15
15
* Transition State Hooks are callback functions that hook into the lifecycle events of specific states during a transition.
16
16
* As a transition runs, it may exit some states, retain (keep) states, and enter states.
17
17
* As each lifecycle event occurs, the hooks which are registered for the event and that state are called (in priority order).
18
18
*
19
- * @param injectables list of services to inject into the function
20
- *
21
- * @returns a [[HookResult]] which may alter the transition
22
- *
23
- * @see
19
+ * #### See also:
24
20
*
25
21
* - [[IHookRegistry.onExit]]
26
22
* - [[IHookRegistry.onRetain]]
27
23
* - [[IHookRegistry.onEnter]]
24
+ *
25
+ * #### Example:
26
+ * ```js
27
+ * onEnter: function() { console.log('Entering'); }
28
+ * ```
29
+ *
30
+ * Not minification-safe
31
+ * ```js
32
+ * onRetain: function($state$) { console.log('Retained ' + $state$.name); }
33
+ * ```
34
+ *
35
+ * Annotated for minification-safety
36
+ * ```js
37
+ * onExit: [ '$transition$', '$state', function($transition$, $state) {
38
+ * // always redirect to 'foo' state when being exited
39
+ * if ($transition$.to().name !== 'foo') {
40
+ * return $state.target('foo');
41
+ * }
42
+ * } ]
43
+ * ```
44
+ *
45
+ * @returns an optional [[HookResult]] which may alter the transition
28
46
*/
29
47
export interface Ng1StateTransitionHook {
30
48
( ...injectables : any [ ] ) : HookResult
31
49
}
32
50
51
+ /**
52
+ * @internalapi
53
+ * an intermediate interface.
54
+ *
55
+ * Used to reset [[StateDeclaration]] typings to `any` so the [[Ng1StateDeclaration]] interface can then narrow them */
56
+ export interface _Ng1StateDeclaration extends StateDeclaration {
57
+ onExit ?: any ;
58
+ onRetain ?: any ;
59
+ onEnter ?: any ;
60
+ }
61
+
33
62
/**
34
63
* The StateDeclaration object is used to define a state or nested state.
35
64
* It should be registered with the [[StateRegistry]].
@@ -95,7 +124,7 @@ export interface Ng1StateTransitionHook {
95
124
* }
96
125
* ```
97
126
*/
98
- export interface Ng1StateDeclaration extends StateDeclaration , Ng1ViewDeclaration {
127
+ export interface Ng1StateDeclaration extends _Ng1StateDeclaration , Ng1ViewDeclaration {
99
128
/**
100
129
* An optional object which defines multiple named views.
101
130
*
@@ -246,7 +275,10 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
246
275
views ?: { [ key : string ] : Ng1ViewDeclaration ; } ;
247
276
248
277
/**
249
- * State hook that can be injected with `$transition$` or `$state$` for the current transition.
278
+ * A state hook invoked when a state is being entered.
279
+ *
280
+ * The hook can inject global services.
281
+ * It can also inject `$transition$` or `$state$` (from the current transition).
250
282
*
251
283
* ### Example:
252
284
* ```js
@@ -257,12 +289,25 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
257
289
* }
258
290
* });
259
291
* ```
292
+ *
293
+ * #### Example:`
294
+ * ```js
295
+ * $stateProvider.state({
296
+ * name: 'mystate',
297
+ * onEnter: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
298
+ * return MyService.doSomething($state$.name, $transition$.params());
299
+ * } ]
300
+ * });
301
+ * ```
260
302
*/
261
- onEnter ?: Ng1StateTransitionHook ;
303
+ onEnter ?: Ng1StateTransitionHook | IInjectable ;
262
304
263
305
/**
264
- * State hook that can be injected with `$transition$` or `$state$` for the current transition.
265
- *
306
+ * A state hook invoked when a state is being exited.
307
+ *
308
+ * The hook can inject global services.
309
+ * It can also inject `$transition$` or `$state$` (from the current transition).
310
+ *
266
311
* ### Example:
267
312
* ```js
268
313
* $stateProvider.state({
@@ -272,13 +317,26 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
272
317
* }
273
318
* });
274
319
* ```
320
+ *
321
+ * #### Example:`
322
+ * ```js
323
+ * $stateProvider.state({
324
+ * name: 'mystate',
325
+ * onExit: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
326
+ * return MyService.doSomething($state$.name, $transition$.params());
327
+ * } ]
328
+ * });
329
+ * ```
275
330
*/
276
- onExit ?: Ng1StateTransitionHook ;
331
+ onExit ?: Ng1StateTransitionHook | IInjectable ;
277
332
278
333
/**
279
- * State hook that can be injected with `$transition$` or `$state$` for the current transition.
280
- *
281
- * ### Example:
334
+ * A state hook invoked when a state is being retained.
335
+ *
336
+ * The hook can inject global services.
337
+ * It can also inject `$transition$` or `$state$` (from the current transition).
338
+ *
339
+ * #### Example:
282
340
* ```js
283
341
* $stateProvider.state({
284
342
* name: 'mystate',
@@ -287,8 +345,18 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
287
345
* }
288
346
* });
289
347
* ```
348
+ *
349
+ * #### Example:`
350
+ * ```js
351
+ * $stateProvider.state({
352
+ * name: 'mystate',
353
+ * onRetain: [ 'MyService', '$transition$', '$state$', function (MyService, $transition$, $state$) {
354
+ * return MyService.doSomething($state$.name, $transition$.params());
355
+ * } ]
356
+ * });
357
+ * ```
290
358
*/
291
- onRetain ?: Ng1StateTransitionHook ;
359
+ onRetain ?: Ng1StateTransitionHook | IInjectable ;
292
360
293
361
/**
294
362
* Makes all search/query parameters `dynamic`
0 commit comments