Sha256: 7d7350ef0396a5f8b11da203ebfdaed9acee6a6927acb812eeb6d95c2db40923

Contents?: true

Size: 1.41 KB

Versions: 52

Compression:

Stored size: 1.41 KB

Contents

# Emitter [![Build Status](https://travis-ci.org/component/emitter.png)](https://travis-ci.org/component/emitter)

  Event emitter component.

## Installation

```
$ component install component/emitter
```

## API

### Emitter(obj)

  The `Emitter` may also be used as a mixin. For example
  a "plain" object may become an emitter, or you may
  extend an existing prototype.

  As an `Emitter` instance:

```js
var Emitter = require('emitter');
var emitter = new Emitter;
emitter.emit('something');
```

  As a mixin:

```js
var Emitter = require('emitter');
var user = { name: 'tobi' };
Emitter(user);

user.emit('im a user');
```

  As a prototype mixin:

```js
var Emitter = require('emitter');
Emitter(User.prototype);
```

### Emitter#on(event, fn)

  Register an `event` handler `fn`.

### Emitter#once(event, fn)

  Register a single-shot `event` handler `fn`,
  removed immediately after it is invoked the
  first time.

### Emitter#off(event, fn)

  * Pass `event` and `fn` to remove a listener.
  * Pass `event` to remove all listeners on that event.
  * Pass nothing to remove all listeners on all events.

### Emitter#emit(event, ...)

  Emit an `event` with variable option args.

### Emitter#listeners(event)

  Return an array of callbacks, or an empty array.

### Emitter#hasListeners(event)

  Check if this emitter has `event` handlers.

## License

MIT

Version data entries

52 entries across 39 versions & 13 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/component-emitter/Readme.md
disco_app-0.18.0 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.18.2 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.16.1 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.15.2 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.18.4 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.18.1 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.14.0 test/dummy/node_modules/component-emitter/Readme.md
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/component-emitter/Readme.md
tang-0.2.1 spec/tang_app/node_modules/component-emitter/Readme.md
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/component-emitter/Readme.md
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/component-emitter/Readme.md
ruby2js-4.0.4 lib/tasks/testrails/node_modules/component-emitter/Readme.md
ruby2js-4.0.3 lib/tasks/testrails/node_modules/component-emitter/Readme.md
tang-0.2.0 spec/tang_app/node_modules/component-emitter/Readme.md
tang-0.1.0 spec/tang_app/node_modules/component-emitter/Readme.md
tang-0.0.9 spec/tang_app/node_modules/component-emitter/Readme.md
enju_library-0.3.8 spec/dummy/node_modules/component-emitter/Readme.md
ilog-0.4.1 node_modules/socket.io-client/node_modules/component-emitter/Readme.md