Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@feizheng/event-mitt

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@feizheng/event-mitt

A mini and light event emitter

  • 2.0.11
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

event-mitt

A mini and light event emitter

version license size download

apis

nameparamsdescription
onname/*,handlerregister an event
offname,handlerunregister an event
emitname,objfire an event
onename,objfire an event,only can register once
oncename,objfire an event,only can execute once

installation

npm install -S @feizheng/event-mitt

usage

import EventMitt from '@feizheng/event-mitt';
const Person = class { };
Object.assign(Person.prototype, EventMitt);
const p1 = new Person();
const sum = 0;
const total = 0;

// attach events:
var res = p1.on('ev1', () => {
  console.log('ev1', sum);
  sum = sum + 1;
});

p1.on('ev2', () => {
  console.log('ev2', sum);
  sum = sum + 3;
});

p1.on('ev3', () => {
  console.log('ev3', sum);
  sum = sum + 5;
});

p1.on('*', (name) => {
  console.log('just a log', name);
  total++;
});

// emit events:
p1.emit('ev1');
p1.emit('ev2');
p1.emit('ev3');

// destory:
res.destroy();

resources

license

Code released under the MIT license.

FAQs

Package last updated on 28 Aug 2020

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc