refactor(core): use `Function.bind` for referring to event listeners instead of a closure.
This commit is contained in:
parent
4d691b61ee
commit
aecb60a604
|
@ -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]))
|
||||
|
|
Loading…
Reference in New Issue