API Docs for: 1.0 pre
Show:

Ember.RSVP.EventTarget Class

Item Index

Methods

Methods

mixin

(
  • object
)
private

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

var object = {};

RSVP.EventTarget.mixin(object);

object.on("finished", function(event) {
  // handle event
});

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

EventTarget.mixin also works with prototypes:

var Person = function() {};
RSVP.EventTarget.mixin(Person.prototype);

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

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

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

yehuda.trigger("poke");
tom.trigger("poke");

Parameters:

  • object Object

    object to extend with EventTarget methods

off

(
  • eventName
  • callback
)
private

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:

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

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

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

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

Parameters:

  • 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

Registers a callback to be executed when eventName is triggered

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

object.trigger('event');

Parameters:

  • eventName String

    name of the event to listen for

  • callback Function

    function to be called when the event is triggered.

trigger

(
  • eventName
  • options
)
private

Use trigger to fire custom events. For example:

object.on('foo', function(){
  console.log('foo event happened!');
});
object.trigger('foo');
// '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){
  console.log(value.name);
});

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

Parameters:

  • eventName String

    name of the event to be triggered

  • options Any

    optional value to be passed to any event handlers for the given eventName