New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easy-eventbus

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-eventbus

this is a library for eventbus

  • 0.4.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

easy-eventbus

一个简单的事件订阅派发的库

如何使用

import eventBus from './eventBus'

// 生成一个观察者
const observer = new eventBus()

// 生成订阅者
const sub = observer.createSubscriber()

// 订阅事件
sub.addListener('test', () => {})

// 派发事件
observer.dispatch('test')

支持使用 script 标签直接引用

<script src='./eventBus.js'></script>
<script>
var observer = new window.eventBus()
// ...
</script>

因为里面用了 defineProperty,所以支持 ie9 以上的浏览器

如何进行开发

git clone git@github.com:rni-l/eventBus.git

cd eventBus

npm i // or cnpm i

// 进行开发
npm run dev

// 打包
npm run build

// 测试
npm run unit

api

const observer = new eventBus()

observer 的属性

属性类型解释
subscribers{Array.}当前存在的订阅者
count{number}当前存在的订阅者数量

observer 的方法

方法说明参数返回值
createSubscriber创建订阅者{Object},返回订阅对象
getSubscriber获取订阅者{id | ?number}{Object | Array.},传 sub.id,返回对象,传空返回全部
removeSubscriber移除订阅者{id | number}{boolean},传 sub.id,返回 true,代表成功
removeAllSubscriber移除全部订阅者
dispatch派发事件{type | string}, {…*}第一个参数是要触发的事件,后面可带任意参数
const sub = observer.createSubsriber()

subscriber 的属性

属性类型解释
id{number}当前的订阅者的 id
listeners{Array.}添加的订阅事件

subscriber 的方法

方法说明参数返回值
addListener添加事件{type | string}, {callback | Function}
removeListener移除事件{type | string}
getListener获取订阅的事件{Array.object}

注意点

  • 重复添加的订阅事件,会覆盖

Keywords

FAQs

Package last updated on 15 Sep 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc