Socket
Socket
Sign inDemoInstall

@braintree/event-emitter

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @braintree/event-emitter

A simple event emitter.


Version published
Weekly downloads
212K
decreased by-12.69%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

import EventEmitter from "@braintree/event-emitter";

class MyClass extends EventEmitter() {
  // my class definition
}

const emitter = new MyClass();

Listen for events

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

emitter.emit("event-name", { payload: "foo" }); // logs "called with foo!"

Unsubscribe from events

const cb = function () {};

emitter.on("event-name", cb);
emitter.off("event-name", cb);

emitter.emit("event-name", { payload: "foo" }); // cb is not called

Tests

npm test

FAQs

Last updated on 07 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc