RSVP.EventTarget Class

Defined in: node_modules/rsvp/lib/rsvp/events.js:19

Module: ember

mixin (object) private

Defined in node_modules/rsvp/lib/rsvp/events.js:24

RSVP.EventTarget.mixin extends an object with EventTarget methods. For Example:

let object = {};


object.on('finished', function(event) {
  // handle event

object.trigger('finished', { detail: value });

EventTarget.mixin also works with prototypes:

let Person = function() {};

let yehuda = new Person();
let tom = new Person();

yehuda.on('poke', function(event) {
  console.log('Yehuda says OW');

tom.on('poke', function(event) {
  console.log('Tom says OW');



object Object
object to extend with EventTarget methods

off (eventName, callback) private

Defined in node_modules/rsvp/lib/rsvp/events.js:109

You can use off to stop firing a particular callback for an event:

function doStuff() { // do stuff! }
object.on('stuff', doStuff);

object.trigger('stuff'); // doStuff will be called

// Unregister ONLY the doStuff callback
object.off('stuff', doStuff);
object.trigger('stuff'); // doStuff will NOT be called

If you don't pass a callback argument to off, ALL callbacks for the event will not be executed when the event fires. For example:

let callback1 = function(){};
let callback2 = function(){};

object.on('stuff', callback1);
object.on('stuff', callback2);

object.trigger('stuff'); // callback1 and callback2 will be executed.

object.trigger('stuff'); // callback1 and callback2 will not be executed!


eventName String
event to stop listening to
callback Function
optional argument. If given, only the function given will be removed from the event's callback queue. If no `callback` argument is given, all callbacks will be removed from the event's callback queue.

on (eventName, callback) private

Defined in node_modules/rsvp/lib/rsvp/events.js:74

Registers a callback to be executed when eventName is triggered

object.on('event', function(eventInfo){
  // handle the event



eventName String
name of the event to listen for
callback Function
function to be called when the event is triggered.

trigger (eventName, options) private

Defined in node_modules/rsvp/lib/rsvp/events.js:163

Use trigger to fire custom events. For example:

object.on('foo', function(){
  console.log('foo event happened!');
// 'foo event happened!' logged to the console

You can also pass a value as a second argument to trigger that will be passed as an argument to all event listeners for the event:

object.on('foo', function(value){

object.trigger('foo', { name: 'bar' });
// 'bar' logged to the console


eventName String
name of the event to be triggered
options *
optional value to be passed to any event handlers for the given `eventName`

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.