summaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@codeispoetry.ru>2017-06-19 19:16:16 +0300
committerAndrej Mihajlov <and@codeispoetry.ru>2017-06-21 12:27:05 +0300
commit912141007dc076924bec8ed25b32d067e19a176b (patch)
tree75bf7ddfdcaef08de17faa43639be8c7c1cf884f /app
parent8ecd87d4df667469414291e81667b10680770f3e (diff)
downloadmullvadvpn-912141007dc076924bec8ed25b32d067e19a176b.tar.xz
mullvadvpn-912141007dc076924bec8ed25b32d067e19a176b.zip
Replace TransitionRule.transitionDescriptor in favor of TransitionMatch
Diffstat (limited to 'app')
-rw-r--r--app/lib/transition-rule.js73
1 files changed, 23 insertions, 50 deletions
diff --git a/app/lib/transition-rule.js b/app/lib/transition-rule.js
index f0c7020870..a91ba4da66 100644
--- a/app/lib/transition-rule.js
+++ b/app/lib/transition-rule.js
@@ -10,65 +10,38 @@ export type TransitionFork = {
backward: TransitionDescriptor
};
-/**
- * Transition rule
- *
- * @class TransitionRule
- */
+export type TransitionMatch = {
+ direction: 'forward' | 'backward',
+ descriptor: TransitionDescriptor
+};
+
export default class TransitionRule {
- from: ?string;
- to: string;
- fork: TransitionFork;
- dir: 'forward' | 'backward' = 'forward';
+ _from: ?string;
+ _to: string;
+ _fork: TransitionFork;
- /**
- * Creates an instance of TransitionRule.
- * @param {string} from - source route to match against, pass null for any.
- * @param {string} to - destination route to match against
- * @param {TransitionFork} fork - transition
- *
- * @memberof TransitionRule
- */
constructor(from: ?string, to: string, fork: TransitionFork) {
- this.from = from;
- this.to = to;
- this.fork = fork;
+ this._from = from;
+ this._to = to;
+ this._fork = fork;
}
- /**
- * Attempts to match the transition between routes A -> B and B -> A
- *
- * @param {string} [fromRoute] source route, pass null for any
- * @param {string} toRoute
- * @returns {boolean} true if matches, otherwise false
- *
- * @memberof TransitionRule
- */
- match(fromRoute: ?string, toRoute: string): boolean {
- if((!this.from || this.from === fromRoute) && this.to === toRoute) {
- this.dir = 'forward';
- return true;
+ 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) {
- this.dir = 'backward';
- return true;
+ if((!this._from || this._from === toRoute) && this._to === fromRoute) {
+ return {
+ direction: 'backward',
+ descriptor: this._fork['backward']
+ };
}
- return false;
- }
-
- /**
- * Returns transition descriptor.
- * Make sure you run match() before to obtain the direction
- * of transition before calling this method
- *
- * @returns {TransitionDescriptor} transitionDescriptor
- *
- * @memberof TransitionRule
- */
- transitionDescriptor(): TransitionDescriptor {
- return this.fork[this.dir];
+ return null;
}
} \ No newline at end of file