These wrappers are not natively understood by ts2dart. Removing them will improve Dart2JS compilation due to fewer megamorphic calls to List functions. It also makes Angular code more succinct and improves type safety in Angular due to better type inference of the Array component type. This change exposed several bugs in Angular.
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import {SpyObject, proxy} from 'angular2/test_lib';
|
|
|
|
import {IMPLEMENTS} from 'angular2/src/facade/lang';
|
|
import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
|
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
|
import {Location} from 'angular2/src/router/location';
|
|
|
|
|
|
@proxy
|
|
@IMPLEMENTS(Location)
|
|
export class SpyLocation extends SpyObject {
|
|
urlChanges: List<string>;
|
|
_path: string;
|
|
_subject: EventEmitter;
|
|
_baseHref: string;
|
|
|
|
constructor() {
|
|
super();
|
|
this._path = '/';
|
|
this.urlChanges = [];
|
|
this._subject = new EventEmitter();
|
|
this._baseHref = '';
|
|
}
|
|
|
|
setInitialPath(url: string) { this._path = url; }
|
|
|
|
setBaseHref(url: string) { this._baseHref = url; }
|
|
|
|
path(): string { return this._path; }
|
|
|
|
simulateUrlPop(pathname: string) { ObservableWrapper.callNext(this._subject, {'url': pathname}); }
|
|
|
|
normalizeAbsolutely(url) { return this._baseHref + url; }
|
|
|
|
go(url: string) {
|
|
url = this.normalizeAbsolutely(url);
|
|
if (this._path == url) {
|
|
return;
|
|
}
|
|
this._path = url;
|
|
this.urlChanges.push(url);
|
|
}
|
|
|
|
forward() {
|
|
// TODO
|
|
}
|
|
|
|
back() {
|
|
// TODO
|
|
}
|
|
|
|
subscribe(onNext, onThrow = null, onReturn = null) {
|
|
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
|
|
}
|
|
|
|
noSuchMethod(m) { return super.noSuchMethod(m); }
|
|
}
|