@@ -88,6 +88,7 @@ export interface TransitionHookOptions {
88
88
hookType ?: string ;
89
89
target ?: any ;
90
90
traceData ?: any ;
91
+ bind ?: any ;
91
92
}
92
93
93
94
/**
@@ -151,7 +152,27 @@ export interface ITransitionService extends IHookRegistry {
151
152
}
152
153
153
154
export 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
+ }
155
176
156
177
/**
157
178
* This interface specifies the api for registering Transition Hooks. Both the
@@ -255,7 +276,7 @@ export interface IHookRegistry {
255
276
* @param callback the hook function which will be injected and invoked.
256
277
* @returns a function which deregisters the hook.
257
278
*/
258
- onBefore ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
279
+ onBefore ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
259
280
260
281
/**
261
282
* Registers a callback function as an `onStart` Transition Hook.
@@ -325,7 +346,7 @@ export interface IHookRegistry {
325
346
* @param callback the hook function which will be injected and invoked.
326
347
* @returns a function which deregisters the hook.
327
348
*/
328
- onStart ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
349
+ onStart ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
329
350
330
351
/**
331
352
* Registers a callback function as an `onEnter` Transition+State Hook.
@@ -394,7 +415,7 @@ export interface IHookRegistry {
394
415
* @param callback the hook function which will be injected and invoked.
395
416
* @returns a function which deregisters the hook.
396
417
*/
397
- onEnter ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
418
+ onEnter ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
398
419
399
420
/**
400
421
* Registers a callback function as an `onRetain` Transition+State Hook.
@@ -432,7 +453,7 @@ export interface IHookRegistry {
432
453
* @param callback the hook function which will be injected and invoked.
433
454
* @returns a function which deregisters the hook.
434
455
*/
435
- onRetain ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
456
+ onRetain ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
436
457
437
458
/**
438
459
* Registers a callback function as an `onExit` Transition+State Hook.
@@ -471,7 +492,7 @@ export interface IHookRegistry {
471
492
* @param callback the hook function which will be injected and invoked.
472
493
* @returns a function which deregisters the hook.
473
494
*/
474
- onExit ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
495
+ onExit ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
475
496
476
497
/**
477
498
* Registers a callback function as an `onFinish` Transition Hook.
@@ -504,7 +525,7 @@ export interface IHookRegistry {
504
525
* @param callback the hook function which will be injected and invoked.
505
526
* @returns a function which deregisters the hook.
506
527
*/
507
- onFinish ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
528
+ onFinish ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
508
529
509
530
/**
510
531
* Registers a callback function as an `onSuccess` Transition Hook.
@@ -531,7 +552,7 @@ export interface IHookRegistry {
531
552
* @param callback the hook function which will be injected and invoked.
532
553
* @returns a function which deregisters the hook.
533
554
*/
534
- onSuccess ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
555
+ onSuccess ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
535
556
536
557
/**
537
558
* Registers a callback function as an `onError` Transition Hook.
@@ -557,7 +578,7 @@ export interface IHookRegistry {
557
578
* @param callback the hook function which will be injected and invoked.
558
579
* @returns a function which deregisters the hook.
559
580
*/
560
- onError ( matchCriteria : IMatchCriteria , callback : IInjectable , options ?) : Function ;
581
+ onError ( matchCriteria : HookMatchCriteria , callback : IInjectable , options ?: HookRegOptions ) : Function ;
561
582
562
583
/**
563
584
* Returns all the registered hooks of a given `hookName` type
@@ -571,13 +592,14 @@ export interface IHookRegistry {
571
592
getHooks ( hookName : string ) : IEventHook [ ] ;
572
593
}
573
594
595
+ /** A predicate type which takes a [[State]] and returns a boolean */
574
596
export type IStateMatch = Predicate < State >
575
597
/**
576
598
* This object is used to configure whether or not a Transition Hook is invoked for a particular transition,
577
599
* based on the Transition's "to state" and "from state".
578
600
*
579
601
* 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 ]])
581
603
*
582
604
* All properties are optional. If any property is omitted, it is replaced with the value `true`, and always matches.
583
605
*
@@ -631,17 +653,17 @@ export type IStateMatch = Predicate<State>
631
653
* }
632
654
* ```
633
655
*/
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 ;
645
667
}
646
668
647
669
export interface IMatchingNodes {
@@ -658,10 +680,11 @@ export interface IMatchingNodes {
658
680
* which should return a boolean to indicate if a state matches.
659
681
* Or, `true` to match anything
660
682
*/
661
- export type MatchCriterion = ( string | IStateMatch | boolean )
683
+ export type HookMatchCriterion = ( string | IStateMatch | boolean )
662
684
663
685
export interface IEventHook {
664
686
callback : IInjectable ;
665
687
priority : number ;
688
+ bind : any ;
666
689
matches : ( treeChanges : TreeChanges ) => IMatchingNodes ;
667
690
}
0 commit comments