@skymapglobal/event-bus
v1.0.2
Published
## Overview
Downloads
20
Readme
Event Bus
Overview
Creating an event bus for pub/sub. Same api with Vue, used for replacing Vue with lightweight size.
Install
yarn add @skymapglobal/event-bus
Usage
import { EventBus } from "@skymapglobal/event-bus";
const bus = new EventBus();
bus.$on("my-event", (a, b) => {
console.log(a, b);
});
bus.$emit("my-event", 'a', 'b');
API
$on(event, listener)
- event: String - event name
- listener: (...params) => void - callback
$once(event, listener)
- event: String - event name
- listener: (...params) => void - callback
$emit(event, ...params)
- event: String - event name
- params?: any[] - any params
$off(event, listener)
- event?: String - event name, ignore to off all
- listener?: Function - callback, ignore to remove all listeners in event