Created
March 15, 2013 12:13
-
-
Save LukeChannings/5169471 to your computer and use it in GitHub Desktop.
Counts the number of listeners attached to a pubsub listener tree.
This file contains hidden or 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
function countListeners(tree) { | |
var count = 0 | |
for (var i in tree) { | |
if (tree.hasOwnProperty(i) && typeof tree[i] === "object") { | |
count += countListeners(tree[i]) | |
} | |
if (typeof tree._listeners === "function") { | |
count += 1 | |
} else if ( tree._listeners instanceof Array ) { | |
count += tree._listeners.length | |
} | |
} | |
return count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
countListeners(pubsubInstance.listenerTree)