Skip to content

Commit

Permalink
fix(Location): make Location#platformStrategy:LocationStrategy proper…
Browse files Browse the repository at this point in the history
…ty 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.
  • Loading branch information
IgorMinar committed Jun 1, 2016
1 parent 7bc2d9a commit e93b3d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions modules/@angular/common/src/location/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@ 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});
});
}

/**
* 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.
Expand All @@ -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
Expand All @@ -99,26 +103,26 @@ 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);
}

/**
* Changes the browsers URL to the normalized version of the given URL, and replaces
* 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.
Expand Down
5 changes: 3 additions & 2 deletions modules/@angular/common/testing/location_mock.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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; }

Expand Down Expand Up @@ -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; }
}

Expand Down

0 comments on commit e93b3d2

Please sign in to comment.