@ienyh/event-dispatcher
v0.0.5
Published
发布订阅封装类,继承即可
Downloads
1
Maintainers
Readme
EventDispatcher
安装
# npm
npm i @ienyh/event-dispatcher --save
用法
import EventDispatcher from "@ienyh/event-dispatcher";
const dispatcher = new EventDispatcher();
dispatcher.addEventListener("change", () => {});
// 支持传入数组且可以为一个事件重复添加监听方法
dispatcher.addEventListener(["tip", "change"], (e) => {
console.log(e);
});
dispatcher.dispatchEvent({ type: "tip" });
或者直接用于继承
import EventDispatcher from "@ienyh/event-dispatcher";
class AController extends EventDispatcher {
constructor() {}
toggle() {
super.dispatchEvent({ type: "change" });
}
}