UNPKG

914 BJavaScriptView Raw
1function broadcast(componentName, eventName, params) {
2 this.$children.forEach(child => {
3 var name = child.$options.componentName;
4
5 if (name === componentName) {
6 child.$emit.apply(child, [eventName].concat(params));
7 } else {
8 broadcast.apply(child, [componentName, eventName].concat([params]));
9 }
10 });
11}
12export default {
13 methods: {
14 dispatch(componentName, eventName, params) {
15 var parent = this.$parent || this.$root;
16 var name = parent.$options.componentName;
17
18 while (parent && (!name || name !== componentName)) {
19 parent = parent.$parent;
20
21 if (parent) {
22 name = parent.$options.componentName;
23 }
24 }
25 if (parent) {
26 parent.$emit.apply(parent, [eventName].concat(params));
27 }
28 },
29 broadcast(componentName, eventName, params) {
30 broadcast.call(this, componentName, eventName, params);
31 }
32 }
33};