perf(RouterLink): use hostListeners for click

with a `<router-outlet>` and lots of `router-link` you start to see
noticeable lag since we’re not removing the listener

Closes #2401
This commit is contained in:
gdi2290 2015-06-08 17:06:10 -07:00 committed by Tobias Bosch
parent a6cb86bab3
commit 92f1af86d8
1 changed files with 7 additions and 5 deletions

View File

@ -33,7 +33,8 @@ import {Location} from './location';
@Directive({
selector: '[router-link]',
properties: ['route: routerLink', 'params: routerParams'],
lifecycle: [onAllChangesDone]
lifecycle: [onAllChangesDone],
hostListeners: {'^click': 'onClick()'}
})
export class RouterLink {
private _domEl;
@ -48,16 +49,17 @@ export class RouterLink {
constructor(elementRef: ElementRef, private _router: Router, private _location: Location) {
this._domEl = elementRef.domElement;
this._params = StringMapWrapper.create();
DOM.on(this._domEl, 'click', (evt) => {
DOM.preventDefault(evt);
this._router.navigate(this._navigationHref);
});
}
set route(changes: string) { this._route = changes; }
set params(changes: StringMap<string, string>) { this._params = changes; }
onClick() {
this._router.navigate(this._navigationHref);
return false;
}
onAllChangesDone(): void {
if (isPresent(this._route) && isPresent(this._params)) {
this._navigationHref = this._router.generate(this._route, this._params);