#

API Docs for: v2.11.1
Show: Inherited Protected Private Deprecated

# RSVP.EventTarget Class

Defined in: `node_modules/rsvp/lib/rsvp/events.js:19`
Module: ember

- Index
- Methods

## Item Index

### Methods

- mixin
- off
- on
- trigger

## Methods

### `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 = {};

    RSVP.EventTarget.mixin(object);

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

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

`EventTarget.mixin` also works with prototypes:

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

    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');
    });

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

#### Parameters:

- `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.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

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
    });

    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

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!');
    });
    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`

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