21 March 2011

Ext JS: relayEvents

I have found that the relayEvents method in Ext JS (2.x) is one of the most useful and code-saving techniques one can use.  The purpose of the method is to allow one object to listen to the custom events of another object.

I have found that the documentation is not that good, which can make somewhat RelayEvents hard to use.  Here is my shorthand to make is easy:


listener.relayEvents(broadcaster, ['custom event a', 'custom event b']);

Where:

  • listener: The object listening for events.  Register the array events in the listeners collection of the object
  • broadcaster: The object firing the events.  To fire the event use the fireEvent('custom event a') method within the broadcaster to fire the event