
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
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 0 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.