Last active
August 29, 2015 14:10
-
-
Save CezaryDanielNowak/f6a34d799d223ac17af2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOMOperationCounter = (function() { | |
var self; | |
if(!window.__DOMOperationCounterCallback) { | |
self = window.__DOMOperationCounterCallback = function(event) { | |
self.counter++; | |
self.details[event.type] = self.details[event.type] ? self.details[event.type] + 1 : 1; | |
} | |
self.counter = 0; | |
self.toggleState = false; | |
self.details = {}; | |
} else { | |
self = window.__DOMOperationCounterCallback; | |
} | |
return function(start) { | |
var events = 'DOMSubtreeModified DOMNodeInserted DOMNodeRemoved DOMNodeRemovedFromDocument DOMNodeInsertedIntoDocument DOMAttrModified DOMCharacterDataModified'; | |
events = events.split(' '); | |
if(start === undefined) { | |
start = self.toggleState = !self.toggleState; | |
} | |
if(start) { | |
self.counter = 0; | |
events.forEach(function(eventName) { | |
document.addEventListener(eventName, window.__DOMOperationCounterCallback, true); | |
}); | |
} else { | |
console.log('Captured DOM events:', self.counter); | |
console.log('DOM events byt type:', self.details); | |
events.forEach(function(eventName) { | |
document.removeEventListener(eventName, window.__DOMOperationCounterCallback, true); | |
}); | |
} | |
return 'Trigger DOMOperationCounter again to see result.'; | |
}; | |
})(); | |
DOMOperationCounter(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment