From abe7d7fedba772c575b53912a2f2cf58773198f9 Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Wed, 13 Nov 2013 14:15:50 -0500 Subject: [PATCH] Remove support for mutation events --- src/ShadowRenderer.js | 7 +--- src/wrappers/HTMLTemplateElement.js | 4 --- src/wrappers/events.js | 51 +++++++++++------------------ 3 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/ShadowRenderer.js b/src/ShadowRenderer.js index 56afed3..c7e4a33 100644 --- a/src/ShadowRenderer.js +++ b/src/ShadowRenderer.js @@ -12,9 +12,7 @@ var ShadowRoot = scope.wrappers.ShadowRoot; var assert = scope.assert; var mixin = scope.mixin; - var muteMutationEvents = scope.muteMutationEvents; var oneOf = scope.oneOf; - var unmuteMutationEvents = scope.unmuteMutationEvents; var unwrap = scope.unwrap; var wrap = scope.wrap; @@ -358,11 +356,8 @@ this.renderNode(shadowRoot, renderNode, node, false); } - if (topMostRenderer) { - //muteMutationEvents(); + if (topMostRenderer) renderNode.sync(); - //unmuteMutationEvents(); - } this.dirty = false; }, diff --git a/src/wrappers/HTMLTemplateElement.js b/src/wrappers/HTMLTemplateElement.js index e218aa3..c8f8867 100644 --- a/src/wrappers/HTMLTemplateElement.js +++ b/src/wrappers/HTMLTemplateElement.js @@ -8,10 +8,8 @@ var HTMLElement = scope.wrappers.HTMLElement; var getInnerHTML = scope.getInnerHTML; var mixin = scope.mixin; - var muteMutationEvents = scope.muteMutationEvents; var registerWrapper = scope.registerWrapper; var setInnerHTML = scope.setInnerHTML; - var unmuteMutationEvents = scope.unmuteMutationEvents; var unwrap = scope.unwrap; var wrap = scope.wrap; @@ -40,11 +38,9 @@ var doc = getTemplateContentsOwner(templateElement.ownerDocument); var df = unwrap(doc.createDocumentFragment()); var child; - muteMutationEvents(); while (child = templateElement.firstChild) { df.appendChild(child); } - unmuteMutationEvents(); return df; } diff --git a/src/wrappers/events.js b/src/wrappers/events.js index 032f6a8..6176a23 100644 --- a/src/wrappers/events.js +++ b/src/wrappers/events.js @@ -179,17 +179,6 @@ return false; } - var mutationEventsAreSilenced = 0; - - function muteMutationEvents() { - mutationEventsAreSilenced++; - } - - function unmuteMutationEvents() { - mutationEventsAreSilenced--; - } - - var OriginalMutationEvent = window.MutationEvent; function dispatchOriginalEvent(originalEvent) { // Make sure this event is only dispatched once. @@ -197,15 +186,9 @@ return; handledEventsTable.set(originalEvent, true); - // Don't do rendering if this is a mutation event since rendering might - // mutate the DOM which would fire more events and we would most likely - // just iloop. - if (originalEvent instanceof OriginalMutationEvent) { - if (mutationEventsAreSilenced) - return; - } else { - scope.renderAllPending(); - } + // Render before dispatching the event to ensure that the event path is + // correct. + scope.renderAllPending(); var target = wrap(originalEvent.target); var event = wrap(originalEvent); @@ -490,13 +473,6 @@ var MouseEvent = registerGenericEvent('MouseEvent', UIEvent, mouseEventProto); var FocusEvent = registerGenericEvent('FocusEvent', UIEvent, focusEventProto); - var MutationEvent = registerGenericEvent('MutationEvent', Event, { - initMutationEvent: getInitFunction('initMutationEvent', 3), - get relatedNode() { - return wrap(this.impl.relatedNode); - }, - }); - // In case the browser does not support event constructors we polyfill that // by calling `createEvent('Foo')` and `initFooEvent` where the arguments to // `initFooEvent` are derived from the registered default event init dict. @@ -569,6 +545,22 @@ return fun && fun.handleEvent; } + function isMutationEvent(type) { + switch (type) { + case 'DOMAttrModified': + case 'DOMAttributeNameChanged': + case 'DOMCharacterDataModified': + case 'DOMElementNameChanged': + case 'DOMNodeInserted': + case 'DOMNodeInsertedIntoDocument': + case 'DOMNodeRemoved': + case 'DOMNodeRemovedFromDocument': + case 'DOMSubtreeModified': + return true; + } + return false; + } + var OriginalEventTarget = window.EventTarget; /** @@ -603,7 +595,7 @@ EventTarget.prototype = { addEventListener: function(type, fun, capture) { - if (!isValidListener(fun)) + if (!isValidListener(fun) || isMutationEvent(type)) return; var listener = new Listener(type, fun, capture); @@ -733,15 +725,12 @@ scope.elementFromPoint = elementFromPoint; scope.getEventHandlerGetter = getEventHandlerGetter; scope.getEventHandlerSetter = getEventHandlerSetter; - scope.muteMutationEvents = muteMutationEvents; - scope.unmuteMutationEvents = unmuteMutationEvents; scope.wrapEventTargetMethods = wrapEventTargetMethods; scope.wrappers.CustomEvent = CustomEvent; scope.wrappers.Event = Event; scope.wrappers.EventTarget = EventTarget; scope.wrappers.FocusEvent = FocusEvent; scope.wrappers.MouseEvent = MouseEvent; - scope.wrappers.MutationEvent = MutationEvent; scope.wrappers.UIEvent = UIEvent; })(window.ShadowDOMPolyfill);