Socket
Socket
Sign inDemoInstall

@saber2pr/event

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @saber2pr/event

Subscribe/Publish


Version published
Weekly downloads
4
decreased by-50%
Maintainers
1
Install size
5.23 kB
Created
Weekly downloads
 

Readme

Source

@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?')

Keywords

FAQs

Last updated on 05 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc