@saber2pr/event

0.1.1 • Public • Published

@saber2pr/event

npm

min-size:[1.01 kb]

Subscribe/Publish

npm install @saber2pr/event

API

subscribe

参数: subscribe(eventName, callback)

eventName可设置为*,表示订阅所有消息(拦截器)

subscribe('test', data => console.log(data))

dispatch

参数:dispatch(eventName, data)

  1. eventName 事件名
  2. data 消息数据

eventName可设置为*,表示发布公共消息(观测者)

dispatch('test', 233)

For Typescript

createAction

参数 createAction<EventNameType, DataType>

type SayHello = createAction<'hello', string>
subscribe<SayHello>('hello', data => console.log(data, '1'))
subscribe<SayHello>('hello', data => console.log(data, '2'))()
subscribe<SayHello>('hello', data => console.log(data, '3'))

dispatch<SayHello>('hello', 'how are you?')

Package Sidebar

Install

npm i @saber2pr/event

Weekly Downloads

0

Version

0.1.1

License

ISC

Unpacked Size

4.36 kB

Total Files

10

Last publish

Collaborators

  • saber2pr