Skip to content

vlavrynovych/simple-event-handler

Repository files navigation

simple-event-handler

A lightweight, framework-agnostic event handler library for both front-end and back-end JavaScript applications. Implement the pub/sub (publisher-subscriber) pattern to decouple your code and enable event-driven architecture. Works seamlessly in browsers, Node.js, and modern JavaScript frameworks like React, Vue, and Angular.

Perfect for managing application-wide events, component communication, real-time updates, and building loosely coupled, maintainable codebases.

Test Coverage Status NPM Version NPM Downloads License: MIT Bundle Size

Features

  • 🚀 Lightweight - Less than 2KB minified
  • 🔧 Zero Dependencies - No external requirements
  • 💪 TypeScript - Full type definitions included
  • 🌐 Universal - Works in browser and Node.js
  • Fast - Optimized for performance
  • 🔗 Method Chaining - Fluent API support
  • 📦 Multiple Formats - UMD, CommonJS, ES Module
  • 100% Test Coverage - Thoroughly tested

Table of Contents

Installation

npm

npm install simple-event-handler

yarn

yarn add simple-event-handler

pnpm

pnpm add simple-event-handler

CDN

<script src="https://unpkg.com/simple-event-handler/dist/simple-event-handler.min.js"></script>

Quick Start

import eventHandler from 'simple-event-handler';

// Subscribe to an event
eventHandler.subscribe('user:login', (user) => {
  console.log('User logged in:', user.name);
});

// Fire the event
eventHandler.fire('user:login', { name: 'John Doe' });

Examples

For comprehensive usage examples including React, Vue, TypeScript, and more, see EXAMPLES.md.

Quick examples:

// Node.js / CommonJS
const eventHandler = require('simple-event-handler');
eventHandler.subscribe('event', (data) => console.log(data));
eventHandler.fire('event', { message: 'Hello!' });

// ES Modules / TypeScript
import eventHandler from 'simple-event-handler';
eventHandler.on('notification', (msg) => console.log(msg));
eventHandler.emit('notification', 'Hello from ESM!');

// Method chaining
eventHandler
  .subscribe('update', (data) => console.log(data))
  .fire('update', { value: 42 })
  .unsubscribeAll('update');

API Documentation

For complete API reference, see API.md.

Quick Reference:

License

MIT - See LICENSE file for details.

About

A lightweight, framework-agnostic event handler library for both front-end and back-end JavaScript applications. Implement the pub/sub (publisher-subscriber) pattern to decouple your code and enable event-driven architecture. Works seamlessly in browsers, Node.js, and modern JavaScript frameworks like React, Vue, and Angular.

Topics

Resources

License

Stars

Watchers

Forks

Contributors