refactor(Router): re-use resolved promise instances

This commit is contained in:
Victor Berchet 2015-06-29 10:40:16 +02:00
parent 1f04f70eda
commit 27ad984626
1 changed files with 8 additions and 5 deletions

View File

@ -8,6 +8,9 @@ import {Instruction} from './instruction';
import {RouterOutlet} from './router_outlet'; import {RouterOutlet} from './router_outlet';
import {Location} from './location'; import {Location} from './location';
let _resolveToTrue = PromiseWrapper.resolve(true);
let _resolveToFalse = PromiseWrapper.resolve(false);
/** /**
* # Router * # Router
* The router is responsible for mapping URLs to components. * The router is responsible for mapping URLs to components.
@ -33,7 +36,7 @@ export class Router {
previousUrl: string = null; previousUrl: string = null;
private _currentInstruction: Instruction = null; private _currentInstruction: Instruction = null;
private _currentNavigation: Promise<any> = PromiseWrapper.resolve(true); private _currentNavigation: Promise<any> = _resolveToTrue;
private _outlet: RouterOutlet = null; private _outlet: RouterOutlet = null;
private _subject: EventEmitter = new EventEmitter(); private _subject: EventEmitter = new EventEmitter();
@ -60,7 +63,7 @@ export class Router {
if (isPresent(this._currentInstruction)) { if (isPresent(this._currentInstruction)) {
return outlet.activate(this._currentInstruction); return outlet.activate(this._currentInstruction);
} }
return PromiseWrapper.resolve(true); return _resolveToTrue;
} }
@ -106,7 +109,7 @@ export class Router {
this.lastNavigationAttempt = url; this.lastNavigationAttempt = url;
return this._currentNavigation = this.recognize(url).then((matchedInstruction) => { return this._currentNavigation = this.recognize(url).then((matchedInstruction) => {
if (isBlank(matchedInstruction)) { if (isBlank(matchedInstruction)) {
return PromiseWrapper.resolve(false); return _resolveToFalse;
} }
if (isPresent(this._currentInstruction)) { if (isPresent(this._currentInstruction)) {
@ -148,7 +151,7 @@ export class Router {
if (isPresent(this._outlet)) { if (isPresent(this._outlet)) {
return this._outlet.activate(instruction); return this._outlet.activate(instruction);
} }
return PromiseWrapper.resolve(true); return _resolveToTrue;
} }
@ -159,7 +162,7 @@ export class Router {
if (isPresent(this._outlet)) { if (isPresent(this._outlet)) {
return this._outlet.deactivate(); return this._outlet.deactivate();
} }
return PromiseWrapper.resolve(true); return _resolveToTrue;
} }