fix(Location): make Location#platformStrategy:LocationStrategy property private

BREAKING CHANGE: Location#platformStrategy property was previously accidentaly exported as public

If any application requires access to the current location strategy, it should be accessed via DI instead
by injecting the LocationStrategy token.

The likelyhood of anyone actually depending on this property is very low.
This commit is contained in:
Igor Minar 2016-05-27 11:29:23 -07:00
parent 7bc2d9a93a
commit e93b3d2360
2 changed files with 16 additions and 11 deletions

View File

@ -52,10 +52,14 @@ export class Location {
/** @internal */
_baseHref: string;
constructor(public platformStrategy: LocationStrategy) {
var browserBaseHref = this.platformStrategy.getBaseHref();
/** @internal */
_platformStrategy: LocationStrategy;
constructor(platformStrategy: LocationStrategy) {
this._platformStrategy = platformStrategy;
var browserBaseHref = this._platformStrategy.getBaseHref();
this._baseHref = Location.stripTrailingSlash(_stripIndexHtml(browserBaseHref));
this.platformStrategy.onPopState((ev) => {
this._platformStrategy.onPopState((ev) => {
ObservableWrapper.callEmit(this._subject, {'url': this.path(), 'pop': true, 'type': ev.type});
});
}
@ -63,7 +67,7 @@ export class Location {
/**
* Returns the normalized URL path.
*/
path(): string { return this.normalize(this.platformStrategy.path()); }
path(): string { return this.normalize(this._platformStrategy.path()); }
/**
* Normalizes the given path and compares to the current normalized path.
@ -90,7 +94,7 @@ export class Location {
if (url.length > 0 && !url.startsWith('/')) {
url = '/' + url;
}
return this.platformStrategy.prepareExternalUrl(url);
return this._platformStrategy.prepareExternalUrl(url);
}
// TODO: rename this method to pushState
@ -99,7 +103,7 @@ export class Location {
* new item onto the platform's history.
*/
go(path: string, query: string = ''): void {
this.platformStrategy.pushState(null, '', path, query);
this._platformStrategy.pushState(null, '', path, query);
}
/**
@ -107,18 +111,18 @@ export class Location {
* the top item on the platform's history stack.
*/
replaceState(path: string, query: string = ''): void {
this.platformStrategy.replaceState(null, '', path, query);
this._platformStrategy.replaceState(null, '', path, query);
}
/**
* Navigates forward in the platform's history.
*/
forward(): void { this.platformStrategy.forward(); }
forward(): void { this._platformStrategy.forward(); }
/**
* Navigates back in the platform's history.
*/
back(): void { this.platformStrategy.back(); }
back(): void { this._platformStrategy.back(); }
/**
* Subscribe to the platform's `popState` events.

View File

@ -1,6 +1,7 @@
import {Injectable, EventEmitter} from '@angular/core';
import {ObservableWrapper} from '../src/facade/async';
import {Location} from '../index';
import {LocationStrategy} from "../src/location/location_strategy";
/**
* A spy for {@link Location} that allows tests to fire simulated location events.
@ -16,6 +17,8 @@ export class SpyLocation implements Location {
_subject: EventEmitter<any> = new EventEmitter();
/** @internal */
_baseHref: string = '';
/** @internal */
_platformStrategy: LocationStrategy = null;
setInitialPath(url: string) { this._history[this._historyIndex].path = url; }
@ -101,8 +104,6 @@ export class SpyLocation implements Location {
return ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
}
// TODO: remove these once Location is an interface, and can be implemented cleanly
platformStrategy: any = null;
normalize(url: string): string { return null; }
}