From 27ad984626a9eadf03f309cc72db707af23cc378 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 29 Jun 2015 10:40:16 +0200 Subject: [PATCH] refactor(Router): re-use resolved promise instances --- modules/angular2/src/router/router.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/angular2/src/router/router.ts b/modules/angular2/src/router/router.ts index 830d1e5c7f..7aadb775d5 100644 --- a/modules/angular2/src/router/router.ts +++ b/modules/angular2/src/router/router.ts @@ -8,6 +8,9 @@ import {Instruction} from './instruction'; import {RouterOutlet} from './router_outlet'; import {Location} from './location'; +let _resolveToTrue = PromiseWrapper.resolve(true); +let _resolveToFalse = PromiseWrapper.resolve(false); + /** * # Router * The router is responsible for mapping URLs to components. @@ -33,7 +36,7 @@ export class Router { previousUrl: string = null; private _currentInstruction: Instruction = null; - private _currentNavigation: Promise = PromiseWrapper.resolve(true); + private _currentNavigation: Promise = _resolveToTrue; private _outlet: RouterOutlet = null; private _subject: EventEmitter = new EventEmitter(); @@ -60,7 +63,7 @@ export class Router { if (isPresent(this._currentInstruction)) { return outlet.activate(this._currentInstruction); } - return PromiseWrapper.resolve(true); + return _resolveToTrue; } @@ -106,7 +109,7 @@ export class Router { this.lastNavigationAttempt = url; return this._currentNavigation = this.recognize(url).then((matchedInstruction) => { if (isBlank(matchedInstruction)) { - return PromiseWrapper.resolve(false); + return _resolveToFalse; } if (isPresent(this._currentInstruction)) { @@ -148,7 +151,7 @@ export class Router { if (isPresent(this._outlet)) { return this._outlet.activate(instruction); } - return PromiseWrapper.resolve(true); + return _resolveToTrue; } @@ -159,7 +162,7 @@ export class Router { if (isPresent(this._outlet)) { return this._outlet.deactivate(); } - return PromiseWrapper.resolve(true); + return _resolveToTrue; }