npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-eventbus

v0.4.6

Published

this is a library for eventbus

Downloads

27

Readme

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 [email protected]: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} |

注意点

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