A minimalism but expressive event bus for JS pub/sub scene. Just for simple scene. You can add your own feature free.
IE / Edge |
Firefox |
Chrome |
Safari |
iOS Safari |
Opera |
---|---|---|---|---|---|
IE8, IE9, IE10, IE11, Edge | last 10 versions | last 10 versions | last 2 versions | last 2 versions | last 2 versions |
yarn add fizz-event-bus --save
import eventBus from "fizz-event-bus";
// ES3 兼容
// import eventBus from "fizz-event-bus/lib/es3/index";
function hander(param) {
console.log(param);
}
eventBus.on("foo", handler);
// somewhere after import from 'fizz-event-bus'
eventBus.emit("foo", "bar");
As default, eventBus is a global object. But you can import the eventBus constructor for create a new EventBus or inherit it.