Created
August 24, 2010 15:39
-
-
Save sfoster/547756 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); | |
} | |
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); | |
} | |
return dus.apply(d, arguments); | |
}; | |
d._connectReport = function(){ | |
var data = dojo.delegate(handleData, { | |
connectDelta: handleData.connect - handleData.disconnect, | |
subscribeDelta: handleData.subscribe - handleData.unsubscribe | |
}); | |
console.log(d.toJson(data, true)); | |
}; | |
})(dojo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment