1.0.4 • Published 12 months ago

svea-bus v1.0.4

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

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();
1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago