
Product
Secure Your AI-Generated Code with Socket MCP
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
vue-eventer
Advanced tools
Vue.js tool known as `event bus` or `even hub` usefull for small projects.
Vue.js tool known as event bus
or even hub
usefull for small projects. Vue 3.x has a lot of breaking changes including removed $on
, $off
and $once
methods so goodbye native event bus. Using this tool you can have the same code for event bus in Vue 2.x and Vue 3.x projects.
To install with npm or yarn, use
npm install --save vue-eventer
// or
yarn add vue-eventer
Methods are compatible with Vue 2.x methods so you can easily switch from native event bus Vue.prototype.$eventBus = new Vue()
to this tool Vue.prototype.$eventBus = new VueEventer()
with no additonal code changes. Later you can again easily switch from Vue 2.x to Vue 3.x.
Adds listener for the event. The callback will receive all the additional arguments passed into $emit()
method. You can also use alias method on()
. Do no forget to always remove listeners in components which can be removed to avoid memory leaks!
Adds one-time listener for the event. The callback will receive all the additional arguments passed into $emit()
method. The listener will be removed once it triggers for the first time. You can also use alias method once()
. Do not forget to always remove listeners in components which can be removed to avoid memory leaks!
Removes listener for the event. You can also use alias method off()
.
Emits event with or without any arguments. Any additional arguments will be passed into the listener’s callback function. You can also use alias method emit()
.
////////// JS for Vue 2.x \\\\\\\\\\
import Vue from 'vue';
import VueEventer from 'vue-eventer';
Vue.prototype.$eventBus = new VueEventer();
const App = new Vue({
el: '#app',
created() {
this.$eventBus.$on('do-sth', this.waitForSomething);
},
beforeDestroy() {
this.$eventBus.$off('do-sth', this.waitForSomething);
},
methods : {
waitForSomething(a, b) {
console.log(a, b);
},
triggerSomething() {
// this.$eventBus.$emit('do-sth', 123);
// this.$eventBus.$emit('do-sth', 123, 456);
// this.$eventBus.$emit('do-sth', { x : 1, y : 2 });
},
},
});
////////// JS for Vue 3.x \\\\\\\\\\
import * as Vue from 'vue';
import VueEventer from 'vue-eventer';
const App = Vue.createApp({
created() {
this.$eventBus.$on('do-sth', this.waitForSomething);
},
beforeUnmount() {
this.$eventBus.$off('do-sth', this.waitForSomething);
},
methods : {
waitForSomething(a, b) {
console.log(a, b);
},
triggerSomething() {
// this.$eventBus.$emit('do-sth', 123);
// this.$eventBus.$emit('do-sth', 123, 456);
// this.$eventBus.$emit('do-sth', { x : 1, y : 2 });
},
},
});
App.config.globalProperties.$eventBus = new VueEventer();
App.mount('#app');
FAQs
Vue.js tool known as `event bus` or `even hub` usefull for small projects.
The npm package vue-eventer receives a total of 162 weekly downloads. As such, vue-eventer popularity was classified as not popular.
We found that vue-eventer 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.
Product
Socket MCP brings real-time security checks to AI-generated code, helping developers catch risky dependencies before they enter the codebase.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.