Chico UI - Doc

v1.0.0

ch.EventEmitter

Description

Event Emitter Class for the browser.

How-to

// Create a new instance of EventEmitter.
var emitter = new ch.EventEmitter();
// Inheriting from EventEmitter.
ch.util.inherits(Widget, ch.EventEmitter);

Methods

.emit(event, var_args)



    

Execute each item in the listener collection in order with the specified data.

  • event - String : The name of the event you want to emit.
  • var_args - Object : Data to pass to the listeners.
// Will emit the 'ready' event with 'param1' and 'param2' as arguments.
widget.emit('ready', 'param1', 'param2');

.getListeners(event) → {Array}



    

Returns all listeners from the collection for a specified event.

  • event - String : The event name.
// Returns listeners from 'ready' event.
widget.getListeners('ready');

.off(event, listener) → {Object}



    

Removes a listener from the collection for a specified event.

  • event - String : Event name.
  • listener - Function : Listener function.
// Will remove event listener to 'ready' event.
widget.off('ready', listener);

.on(event, listener, once)



    

Adds a listener to the collection for a specified event.

  • event - String : The event name to subscribe.
  • listener - Function : Listener function.
  • once - Boolean : Indicate if a listener function will be called only one time.
// Will add an event listener to 'ready' event.
widget.on('ready', listener);

.once(event, listener) → {Object}



    

Adds a listener to the collection for a specified event to will execute only once.

  • event - String : Event name.
  • listener - Function : Listener function.
// Will add an event handler to 'contentLoad' event once.
widget.once('contentLoad', listener);