@@ -88,6 +88,7 @@ export interface TransitionHookOptions {
8888 hookType ?: string ;
8989 target ?: any ;
9090 traceData ?: any ;
91+ bind ?: any ;
9192}
9293
9394/**
@@ -151,7 +152,27 @@ export interface ITransitionService extends IHookRegistry {
151152}
152153
153154export type IHookGetter = ( hookName : string ) => IEventHook [ ] ;
154- export type IHookRegistration = ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) => Function ;
155+ export type IHookRegistration = ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) => Function ;
156+
157+ /**
158+ * These options may be provided when registering a Transition Hook (such as `onStart`)
159+ */
160+ export interface HookRegOptions {
161+ /**
162+ * Sets the priority of the registered hook
163+ *
164+ * Hooks of the same type (onBefore, onStart, etc) are invoked in priority order. A hook with a higher priority
165+ * is invoked before a hook with a lower priority.
166+ *
167+ * The default hook priority is 0
168+ */
169+ priority ?: number ;
170+
171+ /**
172+ * Specifies what `this` is bound to during hook invocation.
173+ */
174+ bind ?: any ;
175+ }
155176
156177/**
157178 * This interface specifies the api for registering Transition Hooks. Both the
@@ -255,7 +276,7 @@ export interface IHookRegistry {
255276 * @param callback the hook function which will be injected and invoked.
256277 * @returns a function which deregisters the hook.
257278 */
258- onBefore ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
279+ onBefore ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
259280
260281 /**
261282 * Registers a callback function as an `onStart` Transition Hook.
@@ -325,7 +346,7 @@ export interface IHookRegistry {
325346 * @param callback the hook function which will be injected and invoked.
326347 * @returns a function which deregisters the hook.
327348 */
328- onStart ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
349+ onStart ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
329350
330351 /**
331352 * Registers a callback function as an `onEnter` Transition+State Hook.
@@ -394,7 +415,7 @@ export interface IHookRegistry {
394415 * @param callback the hook function which will be injected and invoked.
395416 * @returns a function which deregisters the hook.
396417 */
397- onEnter ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
418+ onEnter ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
398419
399420 /**
400421 * Registers a callback function as an `onRetain` Transition+State Hook.
@@ -432,7 +453,7 @@ export interface IHookRegistry {
432453 * @param callback the hook function which will be injected and invoked.
433454 * @returns a function which deregisters the hook.
434455 */
435- onRetain ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
456+ onRetain ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
436457
437458 /**
438459 * Registers a callback function as an `onExit` Transition+State Hook.
@@ -471,7 +492,7 @@ export interface IHookRegistry {
471492 * @param callback the hook function which will be injected and invoked.
472493 * @returns a function which deregisters the hook.
473494 */
474- onExit ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
495+ onExit ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
475496
476497 /**
477498 * Registers a callback function as an `onFinish` Transition Hook.
@@ -504,7 +525,7 @@ export interface IHookRegistry {
504525 * @param callback the hook function which will be injected and invoked.
505526 * @returns a function which deregisters the hook.
506527 */
507- onFinish ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
528+ onFinish ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
508529
509530 /**
510531 * Registers a callback function as an `onSuccess` Transition Hook.
@@ -531,7 +552,7 @@ export interface IHookRegistry {
531552 * @param callback the hook function which will be injected and invoked.
532553 * @returns a function which deregisters the hook.
533554 */
534- onSuccess ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
555+ onSuccess ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
535556
536557 /**
537558 * Registers a callback function as an `onError` Transition Hook.
@@ -557,7 +578,7 @@ export interface IHookRegistry {
557578 * @param callback the hook function which will be injected and invoked.
558579 * @returns a function which deregisters the hook.
559580 */
560- onError ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
581+ onError ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
561582
562583 /**
563584 * Returns all the registered hooks of a given `hookName` type
@@ -571,13 +592,14 @@ export interface IHookRegistry {
571592 getHooks ( hookName : string ) : IEventHook [ ] ;
572593}
573594
595+ /** A predicate type which takes a [[State]] and returns a boolean */
574596export type IStateMatch = Predicate < State >
575597/**
576598 * This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
577599 * based on the Transition's "to state" and "from state".
578600 *
579601 * Each property (`to`, `from`, `exiting`, `retained`, and `entering`) can be state globs, a function that takes a
580- * state, or a boolean (see [[MatchCriterion ]])
602+ * state, or a boolean (see [[HookMatchCriterion ]])
581603 *
582604 * All properties are optional. If any property is omitted, it is replaced with the value `true`, and always matches.
583605 *
@@ -631,17 +653,17 @@ export type IStateMatch = Predicate<State>
631653 * }
632654 * ```
633655 */
634- export interface IMatchCriteria {
635- /** A [[MatchCriterion ]] to match the destination state */
636- to ?: MatchCriterion ;
637- /** A [[MatchCriterion ]] to match the original (from) state */
638- from ?: MatchCriterion ;
639- /** A [[MatchCriterion ]] to match any state that would be exiting */
640- exiting ?: MatchCriterion ;
641- /** A [[MatchCriterion ]] to match any state that would be retained */
642- retained ?: MatchCriterion ;
643- /** A [[MatchCriterion ]] to match any state that would be entering */
644- entering ?: MatchCriterion ;
656+ export interface HookMatchCriteria {
657+ /** A [[HookMatchCriterion ]] to match the destination state */
658+ to ?: HookMatchCriterion ;
659+ /** A [[HookMatchCriterion ]] to match the original (from) state */
660+ from ?: HookMatchCriterion ;
661+ /** A [[HookMatchCriterion ]] to match any state that would be exiting */
662+ exiting ?: HookMatchCriterion ;
663+ /** A [[HookMatchCriterion ]] to match any state that would be retained */
664+ retained ?: HookMatchCriterion ;
665+ /** A [[HookMatchCriterion ]] to match any state that would be entering */
666+ entering ?: HookMatchCriterion ;
645667}
646668
647669export interface IMatchingNodes {
@@ -658,10 +680,11 @@ export interface IMatchingNodes {
658680 * which should return a boolean to indicate if a state matches.
659681 * Or, `true` to match anything
660682 */
661- export type MatchCriterion = ( string | IStateMatch | boolean )
683+ export type HookMatchCriterion = ( string | IStateMatch | boolean )
662684
663685export interface IEventHook {
664686 callback : IInjectable ;
665687 priority : number ;
688+ bind : any ;
666689 matches : ( treeChanges : TreeChanges ) => IMatchingNodes ;
667690}
0 commit comments