open-index/open-npm huggingface dataset:
npm package: @ienyh/event-dispatcher
Description: 发布订阅封装类，继承即可
Author: ienyh
Latest version: 0.0.5

# EventDispatcher

## 安装

```bash
# npm
npm i @ienyh/event-dispatcher --save
```

## 用法

```javascript
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" });
```

或者直接用于继承

```javascript
import EventDispatcher from "@ienyh/event-dispatcher";

class AController extends EventDispatcher {
  constructor() {}

  toggle() {
    super.dispatchEvent({ type: "change" });
  }
}
```