diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 7052b20a7e..5e51da7d44 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -381,10 +381,14 @@ export class ProtoView { 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. - expr.eval(view.context); + if (view.hydrated()) expr.eval(view.context); } }); }); diff --git a/modules/core/test/compiler/view_spec.js b/modules/core/test/compiler/view_spec.js index d0bddb215b..20e69a65b1 100644 --- a/modules/core/test/compiler/view_spec.js +++ b/modules/core/test/compiler/view_spec.js @@ -403,6 +403,54 @@ export function main() { }); }); + describe('event handlers', () => { + var view, ctx, called; + + function createViewAndContext(protoView) { + view = createView(protoView); + ctx = view.context; + called = 0; + ctx.callMe = () => called += 1; + } + + function dispatchClick(el) { + DOM.dispatchEvent(el, DOM.createMouseEvent('click')); + } + + function createProtoView() { + var pv = new ProtoView(el('