@@ -10,26 +10,55 @@ import { StateDeclaration, _ViewDeclaration, IInjectable, Transition, HookResult
1010 *
1111 * State hooks are registered as onEnter/onRetain/onExit in state declarations.
1212 * 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.
1414 *
1515 * Transition State Hooks are callback functions that hook into the lifecycle events of specific states during a transition.
1616 * As a transition runs, it may exit some states, retain (keep) states, and enter states.
1717 * As each lifecycle event occurs, the hooks which are registered for the event and that state are called (in priority order).
1818 *
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:
2420 *
2521 * - [[IHookRegistry.onExit]]
2622 * - [[IHookRegistry.onRetain]]
2723 * - [[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
2846 */
2947export interface Ng1StateTransitionHook {
3048 ( ...injectables : any [ ] ) : HookResult
3149}
3250
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+
3362/**
3463 * The StateDeclaration object is used to define a state or nested state.
3564 * It should be registered with the [[StateRegistry]].
@@ -95,7 +124,7 @@ export interface Ng1StateTransitionHook {
95124 * }
96125 * ```
97126 */
98- export interface Ng1StateDeclaration extends StateDeclaration , Ng1ViewDeclaration {
127+ export interface Ng1StateDeclaration extends _Ng1StateDeclaration , Ng1ViewDeclaration {
99128 /**
100129 * An optional object which defines multiple named views.
101130 *
@@ -246,7 +275,10 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
246275 views ?: { [ key : string ] : Ng1ViewDeclaration ; } ;
247276
248277 /**
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).
250282 *
251283 * ### Example:
252284 * ```js
@@ -257,12 +289,25 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
257289 * }
258290 * });
259291 * ```
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+ * ```
260302 */
261- onEnter ?: Ng1StateTransitionHook ;
303+ onEnter ?: Ng1StateTransitionHook | IInjectable ;
262304
263305 /**
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+ *
266311 * ### Example:
267312 * ```js
268313 * $stateProvider.state({
@@ -272,13 +317,26 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
272317 * }
273318 * });
274319 * ```
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+ * ```
275330 */
276- onExit ?: Ng1StateTransitionHook ;
331+ onExit ?: Ng1StateTransitionHook | IInjectable ;
277332
278333 /**
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:
282340 * ```js
283341 * $stateProvider.state({
284342 * name: 'mystate',
@@ -287,8 +345,18 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
287345 * }
288346 * });
289347 * ```
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+ * ```
290358 */
291- onRetain ?: Ng1StateTransitionHook ;
359+ onRetain ?: Ng1StateTransitionHook | IInjectable ;
292360
293361 /**
294362 * Makes all search/query parameters `dynamic`
0 commit comments