Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created September 8, 2009 17:38
Show Gist options
  • Save lsmith/183091 to your computer and use it in GitHub Desktop.
Save lsmith/183091 to your computer and use it in GitHub Desktop.
YUI({base: '/yui3/build/'}).use('node',function (Y) {
function report(source, context, args) {
console.log(
source, "\n",
"customContext.property( " + context.property + " )", "\n",
"callback args: " + [].slice.call(args).join(','));
}
// From Y.on
// Root of the issue is that the 4th arg is the context, not the event host.
// It treats DOM events specially, but custom events subscribed to with Y.on
// are assumed to be hosted by Y, not the 4th arg.
// Treats the string '#go' as the context
Y.on("click", function (e) {
report("Y.on('click', fn, '#go', customContext, 1, 2, 3)",
this, arguments);
e.currentTarget.fire('custom-event1'); // <-- Assumes node is event host
}, '#go', customContext, 1, 2, 3); // <-- customContext becomes an extra arg
// This is not fired because the subscription assumes Y is the custom event host
// but the fire (above) is done from the Node
Y.on('custom-event1', function (e) {
report("Y.on('custom-event1', fn, '#go', customContext, 4, 5, 6)",
this, arguments);
}, '#go', customContext, 4, 5, 6); // <-- csutomContext becomes an extra arg
Y.one('#go').fire('custom-event1'); // noop because Y assumed to host the event
// From the Node instance
// Asside from the custom event subscriber requiring a different signature than
// the DOM event signature (was not published to send event facade) this works.
Y.one('#go').on('click', function (e) {
report("node.on('click', fn, customContext, 1, 2, 3)",
this, arguments);
e.currentTarget.fire('custom-event2');
}, customContext, 1, 2, 3);
Y.one('#go').on('custom-event2', function (e) {
report("node.on('custom-event2', fn, customContext, 4, 5, 6)",
this, arguments);
}, customContext, 4, 5, 6);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment