Skip to content

Commit

Permalink
perf(RouterLink): use hostListeners for click
Browse files Browse the repository at this point in the history
with a `<router-outlet>` and lots of `router-link` you start to see
noticeable lag since we’re not removing the listener

Closes #2401
  • Loading branch information
PatrickJS authored and tbosch committed Jun 10, 2015
1 parent a6cb86b commit 92f1af8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/angular2/src/router/router_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 92f1af8

Please sign in to comment.