refactor(core): use `Function.bind` for referring to event listeners instead of a closure.

This commit is contained in:
Tobias Bosch 2016-04-29 12:09:29 -07:00
parent 4d691b61ee
commit aecb60a604
1 changed files with 6 additions and 12 deletions

View File

@ -83,14 +83,9 @@ export class CompileEventListener {
listenToRenderer() {
var listenExpr;
var eventListener = o.THIS_EXPR.callMethod('eventHandler', [
o.fn([this._eventParam],
[
new o.ReturnStatement(
o.THIS_EXPR.callMethod(this._methodName, [EventHandlerVars.event]))
],
o.BOOL_TYPE)
]);
var eventListener = o.THIS_EXPR.callMethod(
'eventHandler',
[o.THIS_EXPR.prop(this._methodName).callMethod(o.BuiltinMethod.bind, [o.THIS_EXPR])]);
if (isPresent(this.eventTarget)) {
listenExpr = ViewProperties.renderer.callMethod(
'listenGlobal', [o.literal(this.eventTarget), o.literal(this.eventName), eventListener]);
@ -107,10 +102,9 @@ export class CompileEventListener {
listenToDirective(directiveInstance: o.Expression, observablePropName: string) {
var subscription = o.variable(`subscription_${this.compileElement.view.subscriptions.length}`);
this.compileElement.view.subscriptions.push(subscription);
var eventListener = o.THIS_EXPR.callMethod('eventHandler', [
o.fn([this._eventParam],
[o.THIS_EXPR.callMethod(this._methodName, [EventHandlerVars.event]).toStmt()])
]);
var eventListener = o.THIS_EXPR.callMethod(
'eventHandler',
[o.THIS_EXPR.prop(this._methodName).callMethod(o.BuiltinMethod.bind, [o.THIS_EXPR])]);
this.compileElement.view.createMethod.addStmt(
subscription.set(directiveInstance.prop(observablePropName)
.callMethod(o.BuiltinMethod.SubscribeObservable, [eventListener]))