JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 169600
  • Score
    100M100P100Q192582F
  • License MIT

A simple event emitter.

Package Exports

  • @braintree/event-emitter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@braintree/event-emitter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

event-emitter

A helper module for creating objects with event emitter capabilities.

Installation

npm

npm install --save @braintree/event-emitter

This module uses commonjs. You must use a build tool such as Browserify or Webpack to include it in your frontend project.

Usage

Creating an Object that Inherits from Event Emitter

var EventEmitter = require('@braintree/event-emitter');

function MyClass () {
  EventEmitter.call(this);
}

MyClass.prototype = EventEmitter.createChild(MyClass);

Listen for events

var obj = new MyClass();

obj.on('event-name', function (data) {
  console.log('called with', data.payload, '!');
});

obj._emit('event-name', {payload: 'foo'}); // logs "called with foo!"

Tests

npm test