blob: a91ba4da66d336aef9c27da81a247994caae4221 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// @flow
export type TransitionDescriptor = {
name: string,
duration: number
};
export type TransitionFork = {
forward: TransitionDescriptor,
backward: TransitionDescriptor
};
export type TransitionMatch = {
direction: 'forward' | 'backward',
descriptor: TransitionDescriptor
};
export default class TransitionRule {
_from: ?string;
_to: string;
_fork: TransitionFork;
constructor(from: ?string, to: string, fork: TransitionFork) {
this._from = from;
this._to = to;
this._fork = fork;
}
match(fromRoute: ?string, toRoute: string): ?TransitionMatch {
if((!this._from || this._from === fromRoute) && this._to === toRoute) {
return {
direction: 'forward',
descriptor: this._fork['forward']
};
}
if((!this._from || this._from === toRoute) && this._to === fromRoute) {
return {
direction: 'backward',
descriptor: this._fork['backward']
};
}
return null;
}
}
|