refactor(tests): removed @IMPLEMENTS
This commit is contained in:
@ -18,12 +18,12 @@ export const APP_BASE_HREF: OpaqueToken = CONST_EXPR(new OpaqueToken('appBaseHre
|
||||
*/
|
||||
@Injectable()
|
||||
export class Location {
|
||||
private _subject: EventEmitter = new EventEmitter();
|
||||
private _baseHref: string;
|
||||
_subject: EventEmitter = new EventEmitter();
|
||||
_baseHref: string;
|
||||
|
||||
constructor(public _platformStrategy: LocationStrategy,
|
||||
constructor(public platformStrategy: LocationStrategy,
|
||||
@Optional() @Inject(APP_BASE_HREF) href?: string) {
|
||||
var browserBaseHref = isPresent(href) ? href : this._platformStrategy.getBaseHref();
|
||||
var browserBaseHref = isPresent(href) ? href : this.platformStrategy.getBaseHref();
|
||||
|
||||
if (isBlank(browserBaseHref)) {
|
||||
throw new BaseException(
|
||||
@ -31,48 +31,31 @@ export class Location {
|
||||
}
|
||||
|
||||
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
|
||||
this._platformStrategy.onPopState((_) => this._onPopState(_));
|
||||
this.platformStrategy.onPopState(
|
||||
(_) => { ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true}); });
|
||||
}
|
||||
|
||||
_onPopState(_): void {
|
||||
ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true});
|
||||
}
|
||||
|
||||
path(): string { return this.normalize(this._platformStrategy.path()); }
|
||||
path(): string { return this.normalize(this.platformStrategy.path()); }
|
||||
|
||||
normalize(url: string): string {
|
||||
return stripTrailingSlash(this._stripBaseHref(stripIndexHtml(url)));
|
||||
return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
|
||||
}
|
||||
|
||||
normalizeAbsolutely(url: string): string {
|
||||
if (!url.startsWith('/')) {
|
||||
url = '/' + url;
|
||||
}
|
||||
return stripTrailingSlash(this._addBaseHref(url));
|
||||
}
|
||||
|
||||
_stripBaseHref(url: string): string {
|
||||
if (this._baseHref.length > 0 && url.startsWith(this._baseHref)) {
|
||||
return url.substring(this._baseHref.length);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
_addBaseHref(url: string): string {
|
||||
if (!url.startsWith(this._baseHref)) {
|
||||
return this._baseHref + url;
|
||||
}
|
||||
return url;
|
||||
return stripTrailingSlash(_addBaseHref(this._baseHref, url));
|
||||
}
|
||||
|
||||
go(url: string): void {
|
||||
var finalUrl = this.normalizeAbsolutely(url);
|
||||
this._platformStrategy.pushState(null, '', finalUrl);
|
||||
this.platformStrategy.pushState(null, '', finalUrl);
|
||||
}
|
||||
|
||||
forward(): void { this._platformStrategy.forward(); }
|
||||
forward(): void { this.platformStrategy.forward(); }
|
||||
|
||||
back(): void { this._platformStrategy.back(); }
|
||||
back(): void { this.platformStrategy.back(); }
|
||||
|
||||
subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null,
|
||||
onReturn: () => void = null): void {
|
||||
@ -80,7 +63,19 @@ export class Location {
|
||||
}
|
||||
}
|
||||
|
||||
function _stripBaseHref(baseHref: string, url: string): string {
|
||||
if (baseHref.length > 0 && url.startsWith(baseHref)) {
|
||||
return url.substring(baseHref.length);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function _addBaseHref(baseHref: string, url: string): string {
|
||||
if (!url.startsWith(baseHref)) {
|
||||
return baseHref + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function stripIndexHtml(url: string): string {
|
||||
if (/\/index.html$/g.test(url)) {
|
||||
|
@ -15,7 +15,6 @@ import {
|
||||
List,
|
||||
ListWrapper
|
||||
} from 'angular2/src/core/facade/collection';
|
||||
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
|
||||
|
||||
import {RouteHandler} from './route_handler';
|
||||
import {Url, RootUrl, serializeParams} from './url_parser';
|
||||
|
Reference in New Issue
Block a user