1.1.0 • Published 2 years ago
event-bus-ez v1.1.0
Description
- Simple EventBus (EventEmitter)
- Quick for update. (No need share context with react)
Usage
npm install event-bus-ez --save
Import the module in the place you want to use:
import EventBus from 'event-bus-ez'
Snippet
simple
// EventBus.$emit => notify event(name, data)
// EventBus.$on => register event(name, func)
// EventBus.$once => register event(name, func) one time
// EventBus.$off => off event (name, func)
// EventBus.$offAll => offAll event(name)
// EventBus.$reset => clear all event(name) // clear all
// simple for react-hook js
React.useEffect(() => {
EventBus.$on("NAME_ABC", func)
// EventBus.$on("NAME_DEF", func2)
// EventBus.$on("xzy", func3)
// clean
return function() {
EventBus.$off("NAME_ABC", func)
//...EventBus.$off("NAME_DEF", func2)
}
}, [])
// @ts-ignore
const func = (item, xxx) => {
// do something
alert(item)
}
// from another element
buttonClick = () => {
EventBus.$emit("NAME_ABC", 434, 44)
// EventBus.$emit("NAME_DEF", [434, 44], 44, "434")
}
// __prBusData => dont change it
props
RUN
LIVE EXAMPLE
npm install
npm run dev
npm run start
License
MIT