Skip to content

raphaelameaume/lemonade-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

lemonade-events

lemonade-events is a minimal event system. The implementation is based on mitt with a few changes:

  • It returns the unsuscribe function on subscribe to avoid keeping a reference of the listener function
  • It has a log mode for development
  • It exports an eventBus by default

Installation

npm install lemonade-events

Usage

// import the full instance
import EventBus from "lemonade-events";
// or import only needed methods
import { on, emit } from "lemonade-events";

EventBus.log = true;

let e = '@example / EVENT_NAME';

// subscribe to an event
function listener(data) {
    console.log(data); // { someData: true }
}

let eventListener = EventBus.on(e, listener);

// add subscription
EventBus.emit(e, { someData: true });

// remove subscription
eventListener();
// or
EventBus.off(e, listener);

You can also create an instance of EventBus by yourself if you need.

import { EventBus } from "lemonade-helpers";

let eventBus = EventBus();

// local instance
eventBus.on();
eventBus.emit();

Credits

License

MIT License, see LICENSE for details

About

Minimal event system ๐Ÿ‘€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published