https://github.com/raphaelameaume/lemonade-events
Minimal event system 👀
https://github.com/raphaelameaume/lemonade-events
Last synced: 30 days ago
JSON representation
Minimal event system 👀
- Host: GitHub
- URL: https://github.com/raphaelameaume/lemonade-events
- Owner: raphaelameaume
- License: mit
- Created: 2020-04-11T15:34:18.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-12T14:26:13.000Z (about 5 years ago)
- Last Synced: 2025-04-21T20:55:29.273Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lemonade-events
`lemonade-events` is a minimal event system. The implementation is based on [mitt](https://github.com/developit/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
```js
// 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.
```js
import { EventBus } from "lemonade-helpers";let eventBus = EventBus();
// local instance
eventBus.on();
eventBus.emit();
```## Credits
- [mitt](https://github.com/developit/mitt)## License
MIT License, see [LICENSE](https://github.com/raphaelameaume/lemonade-events/tree/master/LICENSE) for details