From 7f701da66f9354f228c712944f389570baf09ef2 Mon Sep 17 00:00:00 2001 From: Rado Kirov Date: Fri, 16 Jan 2015 16:30:43 -0800 Subject: [PATCH] fix(events): extract eventHandler to new function scope. --- modules/core/src/compiler/view.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 5e51da7d44..0ba733269d 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -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;