Socket
Book a DemoInstallSign in
Socket

@phanan/vuebus

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@phanan/vuebus

A simple event bus for Vue

3.0.1
latest
Source
npmnpm
Version published
Weekly downloads
35
250%
Maintainers
1
Weekly downloads
 
Created
Source

VueBus

A dead-simple event bus for Vue 2.

Installation

Install VueBus with yarn or npm:

yarn add @phanan/vuebus
# or
npm install @phanan/vuebus

Usage

First, import and initialize a new VueBus instance:

import VueBus from '@phanan/vuebus'

const bus = new VueBus()

Emit an event

bus.emit('userLoggedIn')
bus.emit('userLoggedIn', 'with', 'additional', data)

Listen to events

With VueBus, you can listen and react to one event:

bus.on('userLoggedIn', () => this.sayHello())

or an array of events:

bus.on(['userLoggedIn', 'userLoggedBackIn'], () => this.sayHello())

By passing an object of { eventName: callbackFunction } shape, you can listen to several events and react to each of them with a different callback:

bus.on({
  userLoggedIn () {
    this.sayHello()
  },

  userLoggedOut () {
    this.sayGoodbye()
  }
})

once and off

VueBus's once and off behave exactly like their Vue counterparts.

Attach to Vue.prototype

VueBus can attach itself to Vue.prototype and become available as an instance property with the attach function . By default, you can access VueBus as this.$vuebus, but the property name can be customized by passing a string as an argument.

(new VueBus()).attach()

// VueBus is now available as a Vue's instance property
this.$vuebus.emit('userLoggedIn')

// Use a custom property name
(new VueBus()).attach('$bus')
this.$bus.emit('userLoggedIn')

License

MIT © Phan An

FAQs

Package last updated on 20 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.