Skip to content

Instantly share code, notes, and snippets.

@apm
Created July 24, 2009 22:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apm/154595 to your computer and use it in GitHub Desktop.
Save apm/154595 to your computer and use it in GitHub Desktop.
Using custom events to pass data between YUI3 instances.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI3 cross instance communication</title>
<script src="http://yui.yahooapis.com/3.0.0b1/build/yui/yui-debug.js" type="text/javascript"></script>
<body>
<form name="form1">
<input id="button1" type="button" value="Click!" />
</form>
<script type="text/javascript">
YUI().use('event', function(Y) {
var count = 0;
Y.publish('myapp:myevent', {
emitFacade: true,
broadcast: 2
});
Y.on('click', function() {
Y.log('button click');
Y.fire('myapp:myevent', {
count: ++count
});
}, '#button1');
});
YUI().use('event-custom', function(Y) {
Y.Global.on('myapp:myevent', function(e) {
Y.log('received notification from the other instance: ' + e.count);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment