You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

js-simple-events

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-simple-events

Yet another simple event management system

1.2.3
latest
Source
npm
Version published
Maintainers
2
Created
Source

js-simple-events

Yet another simple event management system

npm i -S js-simple-events

About

This is just a simple class that helps to manage events in a simple way without dependencies. It also supports TypeScript!

And it's really light - <1kb in size!

Methods

MethodParamsDescription
emitevent, payloadEmit the event with the given payload.
fireevent, payloadAlias for emit
onevent, callbackListen for the event with the given callback.
listenevent, callbackAlias for on
onceevent, callbackListen for the event once, after handling - remove the listener.
offevent, callbackRemove event listener(s) for the event.
removeevent, callbackAlias for off

Examples

// Import and initialize
import EventManager from 'js-simple-events'

const eventManager = new EventManager();


// Define handlers
const eventHandler = (payload) => console.log('Yay, events work!', payload);

eventManager.on('test', eventHandler);
eventManager.once('test', () => console.log('This will be called just once!'));

// Emit events
eventManager.emit('test', 'Hello!');
// -> Yay, events work! Hello!
// -> This will be called just once!

eventManager.emit('test', 'Hello!');
// -> Yay, events work! Hello!
// (The 'once' handler isn't fired)

Plugins

For Vue.js

Keywords

Simple

FAQs

Package last updated on 16 Oct 2019

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