Yahoo! UI Library

Event Utility 

Yahoo! UI Library > event > YAHOO.util.EventProvider

Class YAHOO.util.EventProvider

EventProvider is designed to be used with YAHOO.augment to wrap CustomEvents in an interface that allows events to be subscribed to and fired by name. This makes it possible for implementing code to subscribe to an event that either has not been created yet, or will not be created at all.


__yui_events - private Object[]

Private storage of custom events

__yui_subscribers - private Object[]

Private storage of custom event subscribers



CustomEvent createEvent ( p_type , p_config )
Creates a new custom event of the specified type. If a custom event by that name already exists, it will not be re-created. In either case the custom event is returned.
p_type <string> the type, or name of the event
p_config <object> optional config params. Valid properties are:
  • scope: defines the default execution scope. If not defined the default scope will be this instance.
  • silent: if true, the custom event will not generate log messages. This is false by default.
  • onSubscribeCallback: specifies a callback to execute when the event has a new subscriber. This will fire immediately for each queued subscriber if any exist prior to the creation of the event.
Returns: CustomEvent
the custom event


boolean fireEvent ( p_type , arguments )
Fire a custom event by name. The callback functions will be executed from the scope specified when the event was created, and with the following parameters:
  • The first argument fire() was executed with
  • The custom object (if any) that was passed into the subscribe() method
p_type <string> the type, or name of the event
arguments <Object*> an arbitrary set of parameters to pass to the handler.
Returns: boolean
the return value from, or null if the custom event does not exist.


void hasEvent ( type )
Returns true if the custom event of the provided type has been created with createEvent.
type <string> the type, or name of the event
Returns: void


void subscribe ( p_type , p_fn , p_obj , p_override )
Subscribe to a CustomEvent by event type
p_type <string> the type, or name of the event
p_fn <function> the function to exectute when the event fires
p_obj <object>
p_obj <Object> An object to be passed along when the event fires
p_override <boolean> If true, the obj passed in becomes the execution scope of the listener
Returns: void


boolean unsubscribe ( p_type , p_fn , p_obj )
Unsubscribes the from the specified event
p_type <string> The type, or name of the event
p_fn <Function> The function to execute
p_obj <Object> The custom object passed to subscribe (optional)
Returns: boolean
true if the subscriber was found and detached.

Copyright © 2006 Yahoo! Inc. All rights reserved.