1.0.2 • Published 1 year ago

sky-eventbus v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

EventBus

A 'eventbus' tool class based on TypeScript encapsulation, which is small in size and convenient for quick use

一个基于TypeScript封装的 eventbus(事件总线) 工具类,体积小,方便快速使用

如何使用呢?(How to use it?)

1、npm安装依赖(to install)

npm install sky-eventbus

2、使用(reference)

  • 导入
import EventBus from 'sky-eventbus'
  • 监听
/*
  eventName 监听事件的名称
  cb 监听的回调函数
*/
EventBus.on("eventName", cb)
EventBus.once("eventName", cb) // 只监听一次
  • 取消监听
/*
  eventName 取消监听的事件名称
  cb 取消监听的回调函数
*/
 EventBus.off("eventName", cb)
  • 发送事件
/*
  eventName 发送事件的名称
  args 发送事件携带的数据
*/
 const args = ['sky', 'test']
 EventBus.emit("eventName", ...args)
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago