sky-eventbus

1.0.2 • Public • Published

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)

Readme

Keywords

Package Sidebar

Install

npm i sky-eventbus

Weekly Downloads

2

Version

1.0.2

License

ISC

Unpacked Size

2.51 kB

Total Files

4

Last publish

Collaborators

  • bluebiubiu