@@ -18,6 +18,7 @@ import {
18
18
IMatchingNodes ,
19
19
HookFn ,
20
20
} from './interface' ;
21
+ import { Transition } from './transition' ;
21
22
import { StateObject } from '../state/stateObject' ;
22
23
import { TransitionEventType } from './transitionEventType' ;
23
24
import { TransitionService } from './transitionService' ;
@@ -35,7 +36,7 @@ import { TransitionService } from './transitionService';
35
36
* - If a function, matchState calls the function with the state and returns true if the function's result is truthy.
36
37
* @returns {boolean }
37
38
*/
38
- export function matchState ( state : StateObject , criterion : HookMatchCriterion ) {
39
+ export function matchState ( state : StateObject , criterion : HookMatchCriterion , transition : Transition ) {
39
40
const toMatch = isString ( criterion ) ? [ criterion ] : criterion ;
40
41
41
42
function matchGlobs ( _state : StateObject ) {
@@ -51,7 +52,7 @@ export function matchState(state: StateObject, criterion: HookMatchCriterion) {
51
52
}
52
53
53
54
const matchFn = < any > ( isFunction ( toMatch ) ? toMatch : matchGlobs ) ;
54
- return ! ! matchFn ( state ) ;
55
+ return ! ! matchFn ( state , transition ) ;
55
56
}
56
57
57
58
/**
@@ -93,9 +94,9 @@ export class RegisteredHook {
93
94
* with `entering: (state) => true` which only matches when a state is actually
94
95
* being entered.
95
96
*/
96
- private _matchingNodes ( nodes : PathNode [ ] , criterion : HookMatchCriterion ) : PathNode [ ] {
97
+ private _matchingNodes ( nodes : PathNode [ ] , criterion : HookMatchCriterion , transition : Transition ) : PathNode [ ] {
97
98
if ( criterion === true ) return nodes ;
98
- const matching = nodes . filter ( node => matchState ( node . state , criterion ) ) ;
99
+ const matching = nodes . filter ( node => matchState ( node . state , criterion , transition ) ) ;
99
100
return matching . length ? matching : null ;
100
101
}
101
102
@@ -132,7 +133,7 @@ export class RegisteredHook {
132
133
* };
133
134
* ```
134
135
*/
135
- private _getMatchingNodes ( treeChanges : TreeChanges ) : IMatchingNodes {
136
+ private _getMatchingNodes ( treeChanges : TreeChanges , transition : Transition ) : IMatchingNodes {
136
137
const criteria = extend ( this . _getDefaultMatchCriteria ( ) , this . matchCriteria ) ;
137
138
const paths : PathType [ ] = values ( this . tranSvc . _pluginapi . _getPathTypes ( ) ) ;
138
139
@@ -144,7 +145,7 @@ export class RegisteredHook {
144
145
const path = treeChanges [ pathtype . name ] || [ ] ;
145
146
const nodes : PathNode [ ] = isStateHook ? path : [ tail ( path ) ] ;
146
147
147
- mn [ pathtype . name ] = this . _matchingNodes ( nodes , criteria [ pathtype . name ] ) ;
148
+ mn [ pathtype . name ] = this . _matchingNodes ( nodes , criteria [ pathtype . name ] , transition ) ;
148
149
return mn ;
149
150
} ,
150
151
{ } as IMatchingNodes
@@ -157,8 +158,8 @@ export class RegisteredHook {
157
158
* @returns an IMatchingNodes object, or null. If an IMatchingNodes object is returned, its values
158
159
* are the matching [[PathNode]]s for each [[HookMatchCriterion]] (to, from, exiting, retained, entering)
159
160
*/
160
- matches ( treeChanges : TreeChanges ) : IMatchingNodes {
161
- const matches = this . _getMatchingNodes ( treeChanges ) ;
161
+ matches ( treeChanges : TreeChanges , transition : Transition ) : IMatchingNodes {
162
+ const matches = this . _getMatchingNodes ( treeChanges , transition ) ;
162
163
163
164
// Check if all the criteria matched the TreeChanges object
164
165
const allMatched = values ( matches ) . every ( identity ) ;
0 commit comments