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

enhance-eventbus

v1.0.6

Published

a enhance eventbus

Downloads

80

Readme

enhance-eventbus

NPM Download NPM Version NPM License PRs Welcome typescript package size

介绍

eventBus 是一个典型的发布订阅模式的实践,而这个包的基础功能就是发布订阅。

eventBusnode.js 中本就自带,所以为什么需要写这个包呢?

其实从包名 enhance-eventbus 中也可以看出来,这是一个增强 (其实是不会起名字) 的 eventBus

它比普通的 eventBus 多了可以在浏览器跨 tab (有同源限制)。

它的 api 跟普通的 eventBus 是一样的使用方式的,极其简单, 相信使用过 vue 里面 eventBusnew 一个 vue 实例作为eventBus)的小伙伴们, 都知道怎么使用~

example

example

StorageEventBus

这里实现原理是利用了 storage 去监听的,所以这里在相同一个 window tab 页面是无法触发事件的,需要开启别的 tab 才能通信。

// yarn add enhance-eventbus or npm i -S enhance-eventbus

const eventBus = new tabeventbus.StorageEventBus({
  isDev: () => true
})

eventBus.on('someEvent', (data) => {

  console.log(data)
})

eventBus.emit('someEvent', {msg: 'hello world'})

use in your vue project

// in the main.js
import enhanceEventbus from "enhance-eventbus"
import Vue from "vue"

Vue.use(enhanceEventbus, {
  type: "storage",
  globalKey: "$eventBus" // 这里配置的是 vue.prototype 挂载的属性名叫什么
})

// and then you can use it by the gloalKey that your define

new Vue({

  mounted() {
    this.$eventBus.on('someEvent', (data) => {
      // ...to do sth
    })

    this.$eventBus.emit('someEvent', data)
  }
})

感谢以下项目(排名不分先后)