emitter.js 1008 B

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