blob: ae0e2ad5b708b007a1cf92cdca5493c3c10c4bae (
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
|
export interface ITransitionDescriptor {
name: string;
duration: number;
}
export interface ITransitionFork {
forward: ITransitionDescriptor;
backward: ITransitionDescriptor;
}
export interface ITransitionMatch {
direction: 'forward' | 'backward';
descriptor: ITransitionDescriptor;
}
export default class TransitionRule {
constructor(private from: string | null, private to: string, private fork: ITransitionFork) {}
public match(fromRoute: string | null, toRoute: string): ITransitionMatch | null {
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;
}
}
|