Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created July 17, 2012 19:48
Show Gist options
  • Select an option

  • Save kara-ryli/3131575 to your computer and use it in GitHub Desktop.

Select an option

Save kara-ryli/3131575 to your computer and use it in GitHub Desktop.
Demonstrates YUI3 event subscription monitoring, for use with performance-intensive events.
YUI().use("widget", function (Y) {
var eventName = "frob",
widg = new Y.Widget(),
ce = widg.publish(eventName);
ce.monitor("attach", function (handler) {
var subs = ce.getSubs();
console.log("handler attached!", subs);
if (!ce.hasSubs()) {
console.log("enabling performance-intensive event");
}
});
ce.monitor("detach", function (handler) {
console.log("handler detached!");
if (!ce.hasSubs()) {
console.log("disabling performance-intensive event");
}
});
widg.on(eventName, function () {}).detach();
widg.on(eventName, function (e) {
console.log("fire: " + e.type);
});
widg.on(eventName, function () {}).detach();
widg.fire(eventName);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment