@@ -68,7 +68,7 @@ export interface TransitionOptions {
68
68
*/
69
69
reload ?: ( boolean | string | StateDeclaration | State ) ;
70
70
/**
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
72
72
*/
73
73
custom ?: any ;
74
74
/** @internal */
@@ -153,22 +153,130 @@ export interface ITransitionService extends IHookRegistry {
153
153
export type IHookGetter = ( hookName : string ) => IEventHook [ ] ;
154
154
export type IHookRegistration = ( matchObject : IMatchCriteria , callback : IInjectable , options ?) => Function ;
155
155
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
+ */
156
160
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 [ ] ;
167
218
}
168
219
169
220
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
+ */
170
268
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
+ */
171
273
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
+ */
172
280
from ?: ( string | IStateMatch ) ;
173
281
}
174
282
0 commit comments