javascriptdom-eventsyui

The purpose of YUI subscribe?


What is the purpose of subscribe? Here is my calendar control:

Code:

var myCal = new yuiCalendar('myCal');
var ripDate = function (type, args) {
   // My code
}

myCal.selectEvent.subscribe(ripDate);

Is this a custom event? Am I overriding the default event? Does this event get fired in the background irrespective if I subscribe to it? In .NET the control events are fired irrespective if you use them or not. How does this differ as to using .on(...)?

Can someone please give a decent description of using subscribe, if there is any documentation (with possible sample code) then it would be appreciated.


Solution

  • YUI has a lot of documentation and examples.

    You are not overriding the event by subscribing to it, you are listening for it, and acting upon any occurrences. You can subscribe as many times as you like, and they will be listened for in the order subscribed.

    Subscribing to a CustomEvent docs

    .on is an alias for AddListener, which is used to listen for DOM events.

    Start with YUI 2's homepage and click around for docs and samples.