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

Commit

Permalink
Remove support for mutation events
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Nov 13, 2013
1 parent 049f71a commit abe7d7f
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 @@ -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.
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

0 comments on commit abe7d7f

Please sign in to comment.