Skip to content

docs(Ng1StateHooks): Corrected interface and docs #3076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/ng1/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ import {IInjectable} from "ui-router-core";
import {Transition} from "ui-router-core";
import {HookResult} from "ui-router-core";


/**
* The signature for Angular 1 State Transition Hooks.
*
* State hooks are registered as onEnter/onRetain/onExit in state declarations.
* State hooks can additionally be injected with $transition$ and $state$ for
* the current [[Transition]] and [[State]] in the transition.
*
* Transition State Hooks are callback functions that hook into the lifecycle events of specific states during a transition.
* As a transition runs, it may exit some states, retain (keep) states, and enter states.
* As each lifecycle event occurs, the hooks which are registered for the event and that state are called (in priority order).
*
* @param injectables list of services to inject into the function
*
* @returns a [[HookResult]] which may alter the transition
*
* @see
*
* - [[IHookRegistry.onExit]]
* - [[IHookRegistry.onRetain]]
* - [[IHookRegistry.onEnter]]
*/
export interface Ng1StateTransitionHook {
(...injectables: any[]) : HookResult
}

/**
* The StateDeclaration object is used to define a state or nested state.
* It should be registered with the [[StateRegistry]].
Expand Down Expand Up @@ -196,6 +222,51 @@ export interface Ng1StateDeclaration extends StateDeclaration, Ng1ViewDeclaratio
*/
views?: { [key: string]: Ng1ViewDeclaration; };

/**
* State hook that can be injected with `$transition$` or `$state$` for the current transition.
*
* ### Example:
* ```js
* $stateProvider.state({
* name: 'mystate',
* onEnter: (MyService, $transition$, $state$) => {
* return MyService.doSomething($state$.name, $transition$.params());
* }
* });
* ```
*/
onEnter?: Ng1StateTransitionHook;

/**
* State hook that can be injected with `$transition$` or `$state$` for the current transition.
*
* ### Example:
* ```js
* $stateProvider.state({
* name: 'mystate',
* onExit: (MyService, $transition$, $state$) => {
* return MyService.doSomething($state$.name, $transition$.params());
* }
* });
* ```
*/
onExit?: Ng1StateTransitionHook;

/**
* State hook that can be injected with `$transition$` or `$state$` for the current transition.
*
* ### Example:
* ```js
* $stateProvider.state({
* name: 'mystate',
* onRetain: (MyService, $transition$, $state$) => {
* return MyService.doSomething($state$.name, $transition$.params());
* }
* });
* ```
*/
onRetain?: Ng1StateTransitionHook;

/**
* Makes all search/query parameters `dynamic`
*
Expand Down