@ienyh/event-dispatcher
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

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

Package Sidebar

Install

npm i @ienyh/event-dispatcher

Weekly Downloads

3

Version

0.0.5

License

MIT

Unpacked Size

6.29 kB

Total Files

6

Last publish

Collaborators

  • ienyh