![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
easy-eventbus
Advanced tools
一个简单的事件订阅派发的库
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
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} |
FAQs
this is a library for eventbus
The npm package easy-eventbus receives a total of 11 weekly downloads. As such, easy-eventbus popularity was classified as not popular.
We found that easy-eventbus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.