Skip to content

Instantly share code, notes, and snippets.

@sdesai
Created October 16, 2012 18:43
Show Gist options
  • Save sdesai/3901162 to your computer and use it in GitHub Desktop.
Save sdesai/3901162 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Testing</title>
<style>
#container {
border:1px solid;
padding:2px;
width: 400px;
}
.item {
border:1px solid grey;
width:100%;
padding:2px;
}
</style>
<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui.js"></script>
</head>
<body>
<script type='text/javascript'>
YUI({filter:"raw", combine:false}).use('node', 'event-custom', function (Y) {
function TestClass() {
this.publish('a', {
emitFacade:true,
defaultFn : function(e) {
console.log(e.type + ": defaultFn");
}
});
this.publish('bar:b', {
emitFacade:true,
broadcast:1,
defaultFn : function(e) {
console.log(e.type + ": defaultFn");
}
});
}
TestClass.prototype.myFire = function() {
this.fire("a", {a:1});
this.fire("bar:b", {b:1}); // pun not intended.
};
Y.augment(TestClass, Y.EventTarget, true, null, [{prefix:'foo'}]);
var t = new TestClass();
Y.on("foo:a", function(e) {
console.log("This shouldn't be hit. a is not broadcasting");
});
Y.on("bar:b", function(e) {
console.log(e.type + ": broadcast to Y");
});
t.on("a" , function(e) {
console.log(e.type + ": listening on t");
});
t.on("bar:b" , function(e) {
console.log(e.type + ": listening on t");
});
t.myFire();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment