Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #306 from arv/remove-mutation-events
Browse files Browse the repository at this point in the history
Remove support for mutation events
  • Loading branch information
Steve Orvell committed Nov 18, 2013
2 parents abdd777 + abe7d7f commit cdd61fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 41 deletions.
7 changes: 1 addition & 6 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -358,11 +356,8 @@
this.renderNode(shadowRoot, renderNode, node, false);
}

if (topMostRenderer) {
//muteMutationEvents();
if (topMostRenderer)
renderNode.sync();
//unmuteMutationEvents();
}

this.dirty = false;
},
Expand Down
4 changes: 0 additions & 4 deletions src/wrappers/HTMLTemplateElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
51 changes: 20 additions & 31 deletions src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,16 @@
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.
if (handledEventsTable.get(originalEvent))
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);
Expand Down Expand Up @@ -491,13 +474,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.
Expand Down Expand Up @@ -583,6 +559,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;

/**
Expand Down Expand Up @@ -617,7 +609,7 @@

EventTarget.prototype = {
addEventListener: function(type, fun, capture) {
if (!isValidListener(fun))
if (!isValidListener(fun) || isMutationEvent(type))
return;

var listener = new Listener(type, fun, capture);
Expand Down Expand Up @@ -747,16 +739,13 @@
scope.elementFromPoint = elementFromPoint;
scope.getEventHandlerGetter = getEventHandlerGetter;
scope.getEventHandlerSetter = getEventHandlerSetter;
scope.muteMutationEvents = muteMutationEvents;
scope.unmuteMutationEvents = unmuteMutationEvents;
scope.wrapEventTargetMethods = wrapEventTargetMethods;
scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
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);

0 comments on commit cdd61fd

Please sign in to comment.