Created
September 15, 2010 21:55
-
-
Save sfoster/581563 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
(function(d){ | |
console.log("Wrapping dojo.connect/subscribe"); | |
var dc = d.connect, | |
ddc = d.disconnect, | |
ds = d.subscribe, | |
dus = d.unsubscribe, | |
uniqueHandleId = 0, | |
handleIds = {}; | |
var handleData = { connect: 0, disconnect: 0, subscribe: 0, unsubscribe: 0 }; | |
d.connect = function() { | |
handleData.connect++; | |
var hdl = dc.apply(d, arguments); | |
hdl._debugId = ++uniqueHandleId; | |
handleIds[hdl._debugId] = "connect"; | |
return hdl; | |
}; | |
d.disconnect = function(handle) { | |
if(handle) { | |
handleData.disconnect++; | |
var hid = ("_debugId" in handle) ? handle._debugId : null; | |
if(hid) { | |
if(hid in handleIds) { | |
// console.log("disconnecting recognized handle: ", hid, handle); | |
delete handleIds[hid]; | |
} else { | |
console.warn("attempt to disconnect previously disconnected handle? ", hid, handle); | |
} | |
} else { | |
console.warn("disconnecting handle without debugId: ", handle); | |
} | |
} else { | |
console.warn("disconnect given falsy handle: ", handle, typeof handle); | |
} | |
return ddc.apply(d, arguments); | |
}; | |
d.subscribe = function() { | |
handleData.subscribe++; | |
var hdl = ds.apply(d, arguments); | |
hdl._debugId = ++uniqueHandleId; | |
handleIds[hdl._debugId] = "subscribe"; | |
return hdl; | |
}; | |
d.unsubscribe = function(handle) { | |
if(handle) { | |
handleData.unsubscribe++; | |
var hid = ("_debugId" in handle) ? handle._debugId : null; | |
if(hid) { | |
if(hid in handleIds) { | |
// console.log("unsubscribing recognized handle: ", hid, handle); | |
delete handleIds[hid]; | |
} else { | |
console.warn("attempt to unsubscribe previously unsubscribed handle? ", hid, handle); | |
} | |
} else { | |
// console.warn("unsubscribing handle without debugId: ", handle); | |
} | |
} else { | |
console.warn("unsubscribe given falsy handle: ", handle, typeof handle); | |
} | |
return dus.apply(d, arguments); | |
}; | |
d._connectReport = function(){ | |
var data = dojo.delegate(handleData, { | |
connectDelta: handleData.connect - handleData.disconnect, | |
subscribeDelta: handleData.subscribe - handleData.unsubscribe, | |
windowUnLoaders: dojo._windowUnloaders.length, | |
onLoaders: dojo._loaders.length, | |
unLoaders: dojo._unloaders.length | |
}); | |
console.log(d.toJson(data, true)); | |
}; | |
})(dojo); |
I edited to reflect an earlier, simpler version and which I was sole author of.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be loaded anytime after dojo.js (the sooner the better). Get the report from the console e.g. > dojo._connectReport()