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

events-constructor

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-constructor

Class for emitting events

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

events-constructor

npm npm bundle size

Class for emitting events

Install

npm

npm install events-constructor

yarn

yarn add events-constructor

Usage

import Events from 'events-constructor';

const eventNames = ['event1', 'event2'];
const events = new Events(initEventNames);

events.on('event1', data => {
  console.log('event1 is called with data:', data);
});

events.trigger('event1', 'some data');

API

events.on

Add listener to event

events.on('event1', data => {
  console.log('event1 is called with data:', data);
});

events.once

Add a listener that will be called only once per event

events.once('event1', data => {
  console.log('event1 is called with data:', data);
});

events.off

Remove listener from event

events.off('event1', data => {
  console.log('event1 is called with data:', data);
});

events.trigger

Trigger event with data

events.trigger('event1', 'some data');

events.removeEventHandlers

Remove all listeners

events.removeEventHandlers();

events.triggers

Get all triggers

events.triggers;

events.deactivate()

Disable event handlers. The trigger method will not produce any effect.

events.on('event1', data => {
  console.log('event1 is called with data:', data); //it's not called
});

events.deactivate();
events.trigger('event1', 'some data');

events.activate()

Enable event handlers.

events.on('event1', data => {
  console.log('event1 is called with data:', data);
});

events.deactivate();
events.trigger('event1', 'some data'); // no effect

events.activate();
events.trigger('event1', 'some data'); // handler is called

events.eachTriggers()

Method for delegate triggers to otherEventsSource(for example)

events.eachTriggers((trigger, eventName) => otherEventsSource.on(eventName, trigger));

Run tests

npm test

Maintainer

👤 Krivega Dmitriy

Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

📝 License

Copyright © 2020 Krivega Dmitriy.
This project is MIT licensed.

FAQs

Package last updated on 21 May 2024

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