A Vue plugin that enables bubbling of custom events vue-bubbler - npm
npm install vue-bubbler
import Vue from 'vue';
import VueBubbler from 'vue-bubbler';
Vue.use(VueBubbler);
vm.$bubble
instead of vm.$emit
{
// ...
methods: {
foo() {
// You can add extra arguments, of course
this.$bubble('foo-called');
}
}
}
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,
// and override existing "$on" instance method.
override: false,
});
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.
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)],
// ...
});
The MIT License.