svea-bus
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

SveaBus

SveaBus is a lightweight event bus library for handling events.

coverage

Installation

You can install SveaBus via npm or yarn:

npm install sveabus

or

yarn add sveabus

Usage

Import the sveaBus function and create a new event bus instance:

import { sveaBus } from 'sveabus';

const bus = sveaBus();

or

import { sveaBus } from 'sveabus';

const {
  on,
  off,
  emit,
  clear,
  eventHandlers,
} = sveaBus();

Event Registration

To register an event handler, use the on method:

bus.on('fire', (data) => {
  console.log('Event received:', data);
});

Event Emission

To emit an event, use the emit method:

bus.emit('fire', 'whats uo?');

Event Handler Removal

To remove an event handler, use the off method:

const handler = (data) => {
  // ...
};

bus.on('fire', handler);

// Later, when you want to remove the event handler
bus.off('fire', handler);

Clearing Event Handlers

To clear all event handlers, use the clear method:

bus.clear();

Readme

Keywords

none

Package Sidebar

Install

npm i svea-bus

Weekly Downloads

1

Version

1.0.4

License

none

Unpacked Size

7.68 kB

Total Files

11

Last publish

Collaborators

  • webdesignberlin