Skip to content

Commit 3a08993

Browse files
docs(*): replace javascript with js
docs(IHookRegistry): Start improving docs for hooks
1 parent 66864ee commit 3a08993

File tree

4 files changed

+147
-96
lines changed

4 files changed

+147
-96
lines changed

src/state/interface.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface ViewDeclaration {
5555
* Injectable provider function that returns the actual controller function or name of a registered controller.
5656
*
5757
* @example
58-
* ```javascript
58+
* ```js
5959
*
6060
* controllerProvider: function(MyResolveData) {
6161
* if (MyResolveData.foo) {
@@ -83,13 +83,13 @@ export interface ViewDeclaration {
8383
* If `template` is a function, it will be called with the State Parameters as the first argument.
8484
*
8585
* @example
86-
* ```javascript
86+
* ```js
8787
*
8888
* template: "<h1>inline template definition</h1><div ui-view></div>"
8989
* ```
9090
*
9191
* @example
92-
* ```javascript
92+
* ```js
9393
*
9494
* template: function(params) {
9595
* return "<h1>generated template</h1>";
@@ -107,13 +107,13 @@ export interface ViewDeclaration {
107107
* If `templateUrl` is a function, it will be called with the State Parameters as the first argument.
108108
*
109109
* @example
110-
* ```javascript
110+
* ```js
111111
*
112112
* templateUrl: "/templates/home.html"
113113
* ```
114114
*
115115
* @example
116-
* ```javascript
116+
* ```js
117117
*
118118
* templateUrl: function(params) {
119119
* return myTemplates[params.pageId];
@@ -128,7 +128,7 @@ export interface ViewDeclaration {
128128
* The template will be used to render the corresponding [[ui-view]] directive.
129129
*
130130
* @example
131-
* ```javascript
131+
* ```js
132132
*
133133
* templateProvider: function(MyTemplateService, params) {
134134
* return MyTemplateService.getTemplate(params.pageId);
@@ -143,7 +143,7 @@ export interface ViewDeclaration {
143143
* It should be registered with the [[$stateProvider]].
144144
*
145145
* @example
146-
* ```javascript
146+
* ```js
147147
*
148148
* // StateDeclaration object
149149
* var foldersState = {
@@ -184,7 +184,7 @@ export interface StateDeclaration extends ViewDeclaration {
184184
* names, e.g., `<a ui-sref="childstate">Child</a>` instead of `<a ui-sref="parentstate.childstate">Child</a>
185185
*
186186
* @example
187-
* ```javascript
187+
* ```js
188188
*
189189
* var parentstate = {
190190
* name: 'parentstate'
@@ -210,7 +210,7 @@ export interface StateDeclaration extends ViewDeclaration {
210210
* - The value (function) is an injectable function which returns the dependency, or a promise for the dependency.
211211
*
212212
* @example
213-
* ```javascript
213+
* ```js
214214
*
215215
* resolve: {
216216
* // If you inject `myStateDependency` into a controller, you'll get "abc"
@@ -258,7 +258,7 @@ export interface StateDeclaration extends ViewDeclaration {
258258
* - `$stateParams`: (deprecated) The parameters for the current state (Note: these parameter values are
259259
*
260260
* @example
261-
* ```javascript
261+
* ```js
262262
*
263263
* resolve: {
264264
* // Define a resolve 'allusers' which delegates to the UserService
@@ -288,7 +288,7 @@ export interface StateDeclaration extends ViewDeclaration {
288288
* See [[UrlMatcher]] for details on acceptable patterns.
289289
*
290290
* @examples
291-
* ```javascript
291+
* ```js
292292
*
293293
* url: "/home"
294294
* // Define a parameter named 'userid'
@@ -316,7 +316,7 @@ export interface StateDeclaration extends ViewDeclaration {
316316
* parameters. For each parameter being configured, add a [[ParamDeclaration]] keyed to the name of the parameter.
317317
*
318318
* @example
319-
* ```javascript
319+
* ```js
320320
*
321321
* params: {
322322
* param1: {
@@ -346,7 +346,7 @@ export interface StateDeclaration extends ViewDeclaration {
346346
* Targets three named ui-views in the parent state's template
347347
*
348348
* @example
349-
* ```javascript
349+
* ```js
350350
*
351351
* views: {
352352
* header: {
@@ -363,7 +363,7 @@ export interface StateDeclaration extends ViewDeclaration {
363363
* ```
364364
*
365365
* @example
366-
* ```javascript
366+
* ```js
367367
* // Targets named ui-view="header" from ancestor state 'top''s template, and
368368
* // named `ui-view="body" from parent state's template.
369369
* views: {

src/transition/hookRegistry.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -75,68 +75,7 @@ export class HookRegistry implements IHookRegistry {
7575

7676
getHooks = (name: string) => this._transitionEvents[name];
7777

78-
/**
79-
* @ngdoc function
80-
* @name ui.router.state.$transitionsProvider#onBefore
81-
* @methodOf ui.router.state.$transitionsProvider
82-
*
83-
* @description
84-
* Registers a function to be injected and invoked before a Transition begins.
85-
*
86-
* This function can be injected with one additional special value:
87-
* - **`$transition$`**: The current transition
88-
*
89-
* @param {object} matchObject An object that specifies which transitions to invoke the callback for (typically this
90-
* value will be {} for this callback, to match all invalid transitions)
91-
*
92-
* - **`to`** - {string|function=} - A glob string that matches the 'to' state's name.
93-
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
94-
* - **`from`** - {string|function=} - A glob string that matches the 'from' state's name.
95-
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
96-
*
97-
* @param {function} callback
98-
* The function which will be injected and invoked, before a matching transition is started.
99-
* The function may optionally return a {boolean|Transition|object} value which will affect the current transition:
100-
*
101-
* @return
102-
* - **`false`** to abort the current transition
103-
* - **{Transition}** A Transition object from the $transition$.redirect() factory. If returned, the
104-
* current transition will be aborted and the returned Transition will supersede it.
105-
* - **{object}** A map of resolve functions to be added to the current transition. These resolves will be made
106-
* available for injection to further steps in the transition. The object should have {string}s for keys and
107-
* {function}s for values, like the `resolve` object in {@link ui.router.state.$stateProvider#state $stateProvider.state}.
108-
*/
10978
onBefore = makeHookRegistrationFn(this._transitionEvents, "onBefore");
110-
111-
/**
112-
* @ngdoc function
113-
* @name ui.router.state.$transitionsProvider#onStart
114-
* @methodOf ui.router.state.$transitionsProvider
115-
*
116-
* @description
117-
* Registers a function to be injected and invoked when a transition has begun. The function is injected in the
118-
* destination state's ResolveContext. This function can be injected with one additional special value:
119-
*
120-
* - **`$transition$`**: The current transition
121-
*
122-
* @param {object} matchObject An object that specifies which transitions to invoke the callback for
123-
*
124-
* - **`to`** - {string|function=} - A glob string that matches the 'to' state's name.
125-
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
126-
* - **`from`** - {string|function=} - A glob string that matches the 'from' state's name.
127-
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
128-
*
129-
* @param {function} callback
130-
* The function which will be injected and invoked, when a matching transition is started.
131-
* The function may optionally return a {boolean|Transition|object} value which will affect the current transition:
132-
*
133-
* - **`false`** to abort the current transition
134-
* - **{Transition}** A Transition object from the $transition$.redirect() factory. If returned, the
135-
* current transition will be aborted and the returned Transition will supersede it.
136-
* - **{object}** A map of resolve functions to be added to the current transition. These resolves will be made
137-
* available for injection to further steps in the transition. The object should have {string}s for keys and
138-
* {function}s for values, like the `resolve` object in {@link ui.router.state.$stateProvider#state $stateProvider.state}.
139-
*/
14079
onStart = makeHookRegistrationFn(this._transitionEvents, "onStart");
14180

14281
/**

src/transition/interface.ts

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface TransitionOptions {
6868
*/
6969
reload ?: (boolean|string|StateDeclaration|State);
7070
/**
71-
* You can define your own Transition Options inside this property and use them, e.g., from a [[TransitionHook]]
71+
* You can define your own Transition Options inside this property and use them, e.g., from a Transition Hook
7272
*/
7373
custom ?: any;
7474
/** @internal */
@@ -153,22 +153,130 @@ export interface ITransitionService extends IHookRegistry {
153153
export type IHookGetter = (hookName: string) => IEventHook[];
154154
export type IHookRegistration = (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
155155

156+
/**
157+
* This interface has the registration functions for Transition Hook instances. Both the
158+
* [[TransitionService]] and also the [[Transition]] object itself implement this interface.
159+
*/
156160
export interface IHookRegistry {
157-
onBefore: IHookRegistration;
158-
onStart: IHookRegistration;
159-
onEnter: IHookRegistration;
160-
onRetain: IHookRegistration;
161-
onExit: IHookRegistration;
162-
onFinish: IHookRegistration;
163-
onSuccess: IHookRegistration;
164-
onError: IHookRegistration;
165-
166-
getHooks: IHookGetter;
161+
/**
162+
* Registers a function as an `onBefore` Transition Hook.
163+
*
164+
* `onBefore` hooks are injected and invoked *before* a Transition starts.
165+
*
166+
* They are invoked synchronously, in priority order, and are typically within the same call stack as
167+
* [[StateService.transitionTo]].
168+
*
169+
* The current [[Transition]] can be injected as `$transition$`
170+
*
171+
* The callback function may return one of three things
172+
* - `false` to abort the current transition
173+
* - A [[TargetState]] object from the $state.target() factory. This will redirect the current transition
174+
* to the target state.
175+
* - A promise
176+
*
177+
* @param matchObject An [[IMatchCriteria]] which defines which Transitions the Hook should be invoked for.
178+
* @param callback The function which will be injected and invoked.
179+
* @returns A function which deregisters the hook.
180+
*/
181+
onBefore(matchObject: IMatchCriteria, callback: IInjectable, options?): Function;
182+
183+
/**
184+
* Registers a function to be injected and invoked when a transition has started.
185+
*
186+
* The function is injected in the destination state's ResolveContext. This function can be injected
187+
* with one additional special value:
188+
*
189+
* -`$transition$`: The current [[Transition]]
190+
*
191+
* @param {object} matchObject An object that specifies which transitions to invoke the callback for
192+
*
193+
* - **`to`** - {string|function=} - A glob string that matches the 'to' state's name.
194+
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
195+
* - **`from`** - {string|function=} - A glob string that matches the 'from' state's name.
196+
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
197+
*
198+
* @param {function} callback
199+
* The function which will be injected and invoked, when a matching transition is started.
200+
* The function may optionally return a {boolean|Transition|object} value which will affect the current transition:
201+
*
202+
* - **`false`** to abort the current transition
203+
* - **{Transition}** A Transition object from the $transition$.redirect() factory. If returned, the
204+
* current transition will be aborted and the returned Transition will supersede it.
205+
* - **{object}** A map of resolve functions to be added to the current transition. These resolves will be made
206+
* available for injection to further steps in the transition. The object should have {string}s for keys and
207+
* {function}s for values, like the `resolve` object in {@link ui.router.state.$stateProvider#state $stateProvider.state}.
208+
*/
209+
onStart(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
210+
onEnter(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
211+
onRetain(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
212+
onExit(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
213+
onFinish(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
214+
onSuccess(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
215+
onError(matchObjectIMatchCriteria, callbackIInjectable, options?): Function;
216+
217+
getHooks(hookNamestring): IEventHook[];
167218
}
168219

169220
export type IStateMatch = Predicate<State>
221+
/**
222+
* This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
223+
* based on the Transition's "to state" and "from state".
224+
*
225+
* The `to` and `from` can be state globs, or a function that takes a state.
226+
* Both `to` and `from` are optional. If one of these is omitted, it is replaced with the
227+
* function: `function() { return true; }`, which effectively matches any state.
228+
*
229+
* @example
230+
* ```js
231+
*
232+
* // This matches a transition coming from the `parent` state and going to the `parent.child` state.
233+
* var match = {
234+
* to: 'parent',
235+
* from: 'parent.child'
236+
* }
237+
* ```
238+
*
239+
* @example
240+
* ```js
241+
*
242+
* // This matches a transition coming from any substate of `parent` and going directly to the `parent` state.
243+
* var match = {
244+
* to: 'parent',
245+
* from: 'parent.**'
246+
* }
247+
* ```
248+
*
249+
* @example
250+
* ```js
251+
*
252+
* // This matches a transition coming from any state and going to any substate of `mymodule`
253+
* var match = {
254+
* to: 'mymodule.**'
255+
* }
256+
* ```
257+
*
258+
* @example
259+
* ```js
260+
*
261+
* // This matches a transition coming from any state and going to any state that has `data.authRequired`
262+
* // set to a truthy value.
263+
* var match = {
264+
* to: function(state) { return !!state.data.authRequired; }
265+
* }
266+
* ```
267+
*/
170268
export interface IMatchCriteria {
269+
/**
270+
* A glob string that matches the 'to' state's name.
271+
* Or, a function with the signature `function(state) {}` which should return a boolean to indicate if the state matches.
272+
*/
171273
to?: (string|IStateMatch);
274+
275+
/**
276+
* A glob string that matches the 'from' state's name.
277+
* Or, a function with the signature `function(State) { return boolean; }` which should return a boolean to
278+
* indicate if the state matches.
279+
*/
172280
from?: (string|IStateMatch);
173281
}
174282

src/transition/transitionService.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {Transition} from "./transition";
99
import {HookRegistry} from "./hookRegistry";
1010
import {TargetState} from "../state/module";
1111
import {Node} from "../path/module";
12+
import {IMatchCriteria} from "./interface";
13+
import {IInjectable} from "../common/common";
14+
import {IEventHook} from "./interface";
1215

1316
/**
1417
* The default transition options.
@@ -31,16 +34,17 @@ class TransitionService implements ITransitionService, IHookRegistry {
3134
this._reinit();
3235
}
3336

34-
onBefore : IHookRegistration;
35-
onStart : IHookRegistration;
36-
onEnter : IHookRegistration;
37-
onRetain : IHookRegistration;
38-
onExit : IHookRegistration;
39-
onFinish : IHookRegistration;
40-
onSuccess : IHookRegistration;
41-
onError : IHookRegistration;
42-
43-
getHooks : IHookGetter;
37+
/** @inheritdoc */
38+
onBefore : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
39+
onStart : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
40+
onEnter : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
41+
onRetain : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
42+
onExit : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
43+
onFinish : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
44+
onSuccess : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
45+
onError : (matchObject: IMatchCriteria, callback: IInjectable, options?) => Function;
46+
47+
getHooks : (hookName: string) => IEventHook[];
4448

4549
private _defaultErrorHandler: ((_error) => void) = function $defaultErrorHandler($error$) {
4650
if ($error$ instanceof Error) console.log($error$);

0 commit comments

Comments
 (0)