1. js-simple-events
Yet another simple event management system
js-simple-events
Package: js-simple-events
Created by: kaskar2008
Last modified: Fri, 06 May 2022 19:29:41 GMT
Version: 1.2.3
License: MIT
Downloads: 477
Repository: https://github.com/kaskar2008/js-simple-events

Install

npm install js-simple-events
yarn add js-simple-events

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

Method Params Description
emit event, payload Emit the event with the given payload.
fire event, payload Alias for emit
on event, callback Listen for the event with the given callback.
listen event, callback Alias for on
once event, callback Listen for the event once, after handling - remove the listener.
off event, callback Remove event listener(s) for the event.
remove event, callback Alias 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

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin