Created
July 17, 2012 19:48
-
-
Save kara-ryli/3131575 to your computer and use it in GitHub Desktop.
Demonstrates YUI3 event subscription monitoring, for use with performance-intensive events.
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
| 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