fix(events): extract eventHandler to new function scope.

This commit is contained in:
Rado Kirov 2015-01-16 16:30:43 -08:00
parent 2381c3640b
commit 7f701da66f
1 changed files with 16 additions and 12 deletions

View File

@ -379,18 +379,7 @@ export class ProtoView {
// TODO(rado): if there is directive at this element that injected an
// event emitter for that eventType do not attach the handler.
MapWrapper.forEach(binder.events, (expr, eventName) => {
DOM.on(element, eventName, (event) => {
if (event.target === element) {
// Most of the time the event will be fired only when the view is
// in the live document. However, in a rare circumstance the
// view might get dehydrated, in between the event queuing up and
// firing.
// TODO(rado): replace with
// expr.eval(new ContextWithVariableBindings(view.context, {'$event': event}));
// when eval with variable bindinds works.
if (view.hydrated()) expr.eval(view.context);
}
});
ProtoView._addNativeEventListener(element, eventName, expr, view);
});
}
}
@ -401,6 +390,21 @@ export class ProtoView {
return view;
}
static _addNativeEventListener(element: Element, eventName: string, expr, view: View) {
DOM.on(element, eventName, (event) => {
if (event.target === element) {
// Most of the time the event will be fired only when the view is
// in the live document. However, in a rare circumstance the
// view might get dehydrated, in between the event queuing up and
// firing.
// TODO(rado): replace with
// expr.eval(new ContextWithVariableBindings(view.context, {'$event': event}));
// when eval with variable bindinds works.
if (view.hydrated()) expr.eval(view.context);
}
});
}
_parentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom {
var p = protoElementInjector.parent;
return isPresent(p) ? preBuiltObjects[p.index].lightDom : null;