| Page 1 of 1 | [ 6 posts ] |
Nate CavanaughYUI Contributor
|
Another random question that I can't seem to get my head around and it's probably just me, but I'm having a hard time figuring out the differences between subscribing to different events.
Nate Cavanaugh
From what I can gather, on is sometimes an alias to addListener and sometimes an alias to subscribe. Is this true, or am I imagining that? Also, the rule I can decipher out is: addListener: for DOM events subscribe for custom events Is that also true? Lastly, this is about event names and consistency. A good example is the following: Code: var panel = new YAHOO.widget.Panel(YAHOO.util.Dom.generateId(), {draggable: true}); panel.setHeader('myTest') panel.render(document.body); panel.subscribe('drag', function(){ console.log('drag', this, arguments); }); panel.dd.subscribe('startDragEvent', function(){ console.log('startDrag', this, arguments); }); I think the confusing part is that in the documentation, the event listed for the panel is dragEvent, but doesn't work when you subscribe to that event name. So is this just a random inconsistency, or is there a method to the madness I'm not seeing, and would be helpful to know? Thanks in advance! |
|
Nate --
There is a reason, but it's not a real good one The reason for the naming issues is that some of the code was written early on in the YUI 2.x timeline and they support an older way of subscribing to events. The newer classes (as well as 3.x) all have a common naming scheme: Code: instance.on('something', function() {}) Does that make sense? |
Nate CavanaughYUI Contributor
|
Dav,
Nate Cavanaugh
Sounds good, now I know to look out for it. Since the docs are slightly misleading (since the event listed is different from the actual event to subscribe to), is there any quick way to know, or is it just testing it out? I think my worry is that as I'm developing, I'll have to write the event signature a couple different ways, even with the docs just to see, which can get maddening, ya know? Thanks again |
|
If there is an event that isn't documented properly, please file a bug for it:
http://yuilibrary.com/projects/yui2/newticket That's the best way to get it fixed.. |
Nate CavanaughYUI Contributor
|
That I will do, however, I'm noticing something here: would it be safe to assume that if it's listed as a custom event, it's always a property on that object?
Nate Cavanaugh
For instance, when it says dragEvent as the custom event of DragDrop, does that mean every instance has a dragEvent property like so: var dragItem = new YAHOO.util.DD(el, options); dragItem.dragEvent.subscribe ? If so, it could simply be a bug in my brains programming and not the documentation For some reason, I always believed the custom events to be keys to subscribe to, not properties on that object. If I'm wrong on this one, too, I'll file a ticket |
|
Nate --
There are 2 main types of event subscriptions: Events ExampleClick here to see the revision history on this Gist.They should be noted per component in either the API docs or their landing pages. |
| Page 1 of 1 | [ 6 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group