New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

event-controller

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-controller

Simple JavaScript event controller implementation

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

SYNOPSIS

Simple JavaScript event controller implementation. Similar to Node.js EventEmitter, but manages a single event type.

  • Useful for building interfaces that favor composition over inheritance. Event controllers could be assigned to instance properties instead of using inherited EventEmitter.
  • Manages a single event, avoids extra event type lookup. Can't dispatch arbitrary events, each event type needs its own controller.
  • Doesn't rely on strings to identify event types.
  • Might be faster (see benchmark below).

Build Status

USAGE

var EventController = require('event-controller');
var event1 = new EventController();

// Add listener
event1.add(function (value) {
  // handle event
});

// Dispatch
event1.dispatch('hello');

Interface example:

function MyObject() {
  this.onError = new EventController();
  this.onReceive = new EventController();
}

var obj = new MyObject();

// Add error handler
obj.onError.add(function() {});

// Dispatch error
obj.onError.dispatch(new Error());

##API

###.add(fn)

Add new event listener.

###.remove(fn)

Remove event listener.

###.dispatch(args...) .raise(args...)

Dispatch new event.

##BENCHMARK

Random benchmark results for 1 event type and 2 listeners .

EventEmitter x 1,269,447 ops/sec ±3.63% (85 runs sampled)
EventController x 3,427,809 ops/sec ±2.19% (88 runs sampled)
Fastest is EventController

##LICENSE

Apache License, Version 2.0

Keywords

runtime

FAQs

Package last updated on 19 Apr 2015

Did you know?

Socket

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