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

@shuzhong/vue-event-bus

v1.1.3

Published

A light weight vue event bus

Downloads

12

Readme

#+TITLE: @shuzhong/vue-event-bus #+AUTHOR: ShuZhong #+EMAIL: [email protected]

Read this in other languages: [[README.zh.org][简体中文]] [[README.org][English]]

  • Feature
  1. Optional =strict= mode, only accept predefined =events=
  2. Auto remove event listeners (include anonymous function) in Vue beforeDestroy hook
  3. Event param can be =string | string[]=, on/off/fire multiple events
  4. Bind =this= to target Vue component
  • Install #+BEGIN_SRC shell-script npm install --save @shuzhong/vue-event-bus #+END_SRC

  • Setup

commonjs #+BEGIN_SRC js var VueEventBus = require('@shuzhong/vue-event-bus')

Vue.use(VueEventBus) // default options // or Vue.use(VueEventBus, { events: ['EVENT-NAME-1', 'EVENT-NAME-2', 'EVENT-NAME-3'], strict: true }) #+END_SRC

ES2015+ #+BEGIN_SRC js import VueEventBus from '@shuzhong/vue-event-bus'

Vue.use(VueEventBus) // default options // or Vue.use(VueEventBus, { events: ['EVENT-NAME-1', 'EVENT-NAME-2', 'EVENT-NAME-3'], strict: true }) #+END_SRC

External #+BEGIN_SRC html

#+END_SRC

  • Usage

CompOne.vue #+BEGIN_SRC javascript // ............. mounted() { // Because this bind to CompOne, The next 4 this points to the same context this.$busOn('EVENT_1', () => { console.log(this, '11') }) // Bind by ES6 arrow function this.$busOn('EVENT_2', function() { console.log(this, '12') }) // Bind by VueEventBus this.$busOnce('EVENT_3', () => { console.log(this, '13') }) // Bind by ES6 arrow function this.$busOn('EVENT_4', this.busOnFunc1) // Bind by Vue (Vue Methods auto bind this)

// listen multiple events
this.$busOn(['EVENT_1', 'EVENT_2', 'EVENT_3'], function() { })

},

beforeDestroy() { this.$busOff('EVENT_4', this.busOnFunc1)

// Destory multiple events (Clear all listeners for this event when the second argument is not passed)
this.$busOff(['EVENT_1', 'EVENT_2', 'EVENT_3'])

},

methods: { busOnFunc1() { console.log(this, '14') } } // ........... #+END_SRC

CompTwo.vue #+BEGIN_SRC javascript this.$busFire('EVENT_1', 'arg1', 'arg2', [1, 2, 3, 4])

// Trigger multiple events in sequence this.$busFire(['EVENT_1', 'EVENT_2', 'EVENT_3', 'EVENT_4']) this.$busFire(['EVENT_1', 'EVENT_2', 'EVENT_3', 'EVENT_4'], 'arg1', 'arg2', [1, 2, 3, 4]) #+END_SRC

  • API ** Install option #+BEGIN_SRC typescript type Options = { strict: boolean events: string[] }

Vue.use(VueEventBus, options?: Options = { strict: false, events: [] }) #+END_SRC

options:

  • strict: { type: boolean, default: false }
  • events: { type: string[], default: [] }

When =strict= is =true=, only event declared in =events= are legal. If an undeclared event is on/off/fire, an error is thrown.

** Listen event #+BEGIN_SRC typescript this.$busOn(evTag: string | string[], evFunc: Function) this.$busOnce(evTag: string | string[], evFunc: Function) #+END_SRC

** Remove event #+BEGIN_SRC typescript this.$busOff(evTag: string | string[], evFunc?: Function) #+END_SRC

Clear all event listeners corresponding to =evTag= when the =evFunc= param is not passed.

** Fire event #+BEGIN_SRC typescript this.$busFire(evTag: string | string[], ...args: any[]) #+END_SRC

  • License MIT