PDA

View Full Version : difference between onEvent.subscribe and addListener(event



sjivan
26 Nov 2006, 11:26 AM
What the difference between


um.onUpdate.subscribe(myFcnNeedsToKnow);


and


mgr.addListener('update', myFcnNeedsToKnow);


Are the two basically the same?

Also is mgr.on('update', myFcnNeedsToKnow) also a third way to accomplish the same thing?

Which API do you recommend?

Thanks,
Sanjiv

arnair
26 Nov 2006, 12:24 PM
um.onUpdate.subscribe(myFcnNeedsToKnow);
This subscribes directly to YUI's CustomEvent object. More information on that here:
http://developer.yahoo.com/yui/event/#customdefine


mgr.addListener('update', myFcnNeedsToKnow);
mgr.on('update', myFcnNeedsToKnow)
These two use Jack's Observable class defined in yutil.js ('on' is just an alias for 'addListener'). IMO, this is cleaner as you can now subscribe to an object's events using their names, as opposed to the event objects themselves. Guess the YUI guys realized this as well, which is why YUI 0.12 has a similar EventProvider class...

You can get more information on the Observable class from YUI/Ext javadocs. Many of the YUI/Ext classes also implement it, so you can take a look at those as well to figure out how to use it.

jack.slocum
26 Nov 2006, 3:39 PM
The raw CustomEvent access (um.onUpdate.subscribe(myFcnNeedsToKnow);) is deprecated as well.

sjivan
28 Nov 2006, 12:37 PM
Can you update the sample on the doc for UpdateManager to not use um.onUpdate.subscribe. That confused me some as I could not see the UpdateManager onUpdate in the doc API yet the sample had it.

Thanks,
Sanjiv

jack.slocum
28 Nov 2006, 5:57 PM
Updated in the code. ;)