vue-bubbler
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

vue-bubbler

CircleCI

A Vue plugin that enables bubbling of custom events vue-bubbler - npm

Usage

1. Install package

npm install vue-bubbler

2. Vue.use it

import Vue from 'vue';
import VueBubbler from 'vue-bubbler';
 
Vue.use(VueBubbler);

3. Emit custom events with vm.$bubble instead of vm.$emit

{
    // ...
    methods: {
        foo() {
            // You can add extra arguments, of course
            this.$bubble('foo-called');
        }
    }
}

Options

Vue.use(VueBubbler, {
    shouldPropagate(child, parent, event, args) {
        // You should return true if you want components to propagate custom events.
        // By default this is undefined, all events will be propagated.
        return true;
    },
 
    // When true, vue-bubbler will NOT add new "$bubble" instance method,
    // instead overrides existing "$on" instance method.
    override: false,
});

Sealing Extension

vue-bubbler includes official extension vue-bubbler/sealing.

This adds vm.$sealed custom property, which decides whether the component propagates custom events by $bubble method.

Usage

In bootstrap:

import Vue from 'vue';
import VueBubbler from 'vue-bubbler';
import { preventSealedComponents } from 'vue-bubbler/sealing';
 
Vue.use(VueBubbler, {
    shouldPropagate: preventSealedComponents,
});

In component:

import Vue from 'vue';
import { sealed } from 'vue-bubbler/sealing';
 
Vue.extend({
    // Now this component prevent propagation with $bubble.
    mixins: [sealed(true)],
    // ...
});

License

The MIT License.

Readme

Keywords

Package Sidebar

Install

npm i vue-bubbler

Weekly Downloads

9

Version

2.0.3

License

MIT

Unpacked Size

6.44 kB

Total Files

6

Last publish

Collaborators

  • kb10uy