unsubscribe.html revision 1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI 3.0</title>
<script type="text/javascript" src="/build/yui-debug.js"></script>
<body>
<input id="button1" type="button" value="Button 1" class='button' />
<input id="button2" type="button" value="Button 2" class='button' />
<script>
(function() {
//var Y = YUI().use('event', 'dom');
var Y = YUI().use('dump');
var obj = new Y.Event.Target();
Y.on('yui:log', function() {
console.log('LOG NOTIFICATION (console): ' + Y.Lang.dump(Y.Array(arguments)));
Y.log('log NOTIFICATION (Y.log): ' + Y.Lang.dump(Y.Array(arguments)));
});
Y.Event.onDOMReady(function() {
Y.log("onDOMReady fired");
});
var el = Y.get('button1');
Y.log("got " + el);
Y.on('click', function(e) {
Y.log(this.id + " click event facade: " + e.target);
}, el);
var ret = Y.on('click', function(e) {
Y.log(this.id + " click event facade: " + e.target);
}, 'button2');
Y.log('ret: ' + ret);
// Y.on('mouseover', function(e) {
// Y.log(this.id + " mouseover: " + e.target);
// }, Y.Node.getElementsByClassName('button'));
Y.on('TEST:EVENT', function() {
Y.log('test event subscriber success: ' + Y.Array(arguments));
});
Y.fire('TEST:EVENT', 1, 2);
Y.fire('asdf:asdf', 1);
Y.fire('asdf', 1);
var h = obj.subscribe('foo', function() {
console.info('subscriber 1 executed: ' + Y.Array(arguments));
});
Y.log('h: ' + Y.Lang.dump(h));
Y.log('sub 1 should execute');
obj.fire('foo', 1);
h.detach();
Y.log('nothing should execute');
obj.fire('foo', 2);
var h = obj.subscribe('foo', function() {
console.info('subscriber 2 executed: ' + Y.Array(arguments));
});
Y.log('sub 2 should execute');
obj.fire('foo', 3);
obj.unsubscribe(h);
Y.log('nothing should execute');
obj.fire('foo', 4);
Y.on('yui:log', function() {
obj.fire('log recursion', 5);
Y.log('recurse');
});
/*
// test failure
obj.subscribe('foo', function() {
console.info(notdefined);
});
obj.subscribe('foo', function() {
console.info(notdefined);
});
obj.subscribe('foo', function() {
console.info('foo fired anyway!');
});
try {
obj.fire('foo');
} catch(e) {
console.warn('fire() error: ' + Y.Lang.dump(e.errors));
}
*/
})();
</script>
</body>
</html>