Skip to content

Commit 7f701da

Browse files
committed
fix(events): extract eventHandler to new function scope.
1 parent 2381c36 commit 7f701da

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

modules/core/src/compiler/view.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,7 @@ export class ProtoView {
379379
// TODO(rado): if there is directive at this element that injected an
380380
// event emitter for that eventType do not attach the handler.
381381
MapWrapper.forEach(binder.events, (expr, eventName) => {
382-
DOM.on(element, eventName, (event) => {
383-
if (event.target === element) {
384-
// Most of the time the event will be fired only when the view is
385-
// in the live document. However, in a rare circumstance the
386-
// view might get dehydrated, in between the event queuing up and
387-
// firing.
388-
// TODO(rado): replace with
389-
// expr.eval(new ContextWithVariableBindings(view.context, {'$event': event}));
390-
// when eval with variable bindinds works.
391-
if (view.hydrated()) expr.eval(view.context);
392-
}
393-
});
382+
ProtoView._addNativeEventListener(element, eventName, expr, view);
394383
});
395384
}
396385
}
@@ -401,6 +390,21 @@ export class ProtoView {
401390
return view;
402391
}
403392

393+
static _addNativeEventListener(element: Element, eventName: string, expr, view: View) {
394+
DOM.on(element, eventName, (event) => {
395+
if (event.target === element) {
396+
// Most of the time the event will be fired only when the view is
397+
// in the live document. However, in a rare circumstance the
398+
// view might get dehydrated, in between the event queuing up and
399+
// firing.
400+
// TODO(rado): replace with
401+
// expr.eval(new ContextWithVariableBindings(view.context, {'$event': event}));
402+
// when eval with variable bindinds works.
403+
if (view.hydrated()) expr.eval(view.context);
404+
}
405+
});
406+
}
407+
404408
_parentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom {
405409
var p = protoElementInjector.parent;
406410
return isPresent(p) ? preBuiltObjects[p.index].lightDom : null;

0 commit comments

Comments
 (0)