UNPKG

wetrade-design

Version:

一款多语言支持Vue3的UI框架

56 lines 1.7 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; var GraphEvent = /*#__PURE__*/function () { function GraphEvent() { _classCallCheck(this, GraphEvent); this.listeners = {}; } _createClass(GraphEvent, [{ key: "add", value: function add(type, callback) { if (!(type in this.listeners)) { this.listeners[type] = []; } this.listeners[type].push(callback); } }, { key: "remove", value: function remove(type, callback) { if (!(type in this.listeners)) { return; } var stack = this.listeners[type]; for (var i = 0, l = stack.length; i < l; i++) { if (stack[i] === callback) { stack.splice(i, 1); return this.remove(type, callback); } } } }, { key: "dispatch", value: function dispatch(event) { var _this = this; var breakOff = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!(event.type in this.listeners)) { return; } var stack = this.listeners[event.type]; event.target = this; if (breakOff) { stack.some(function (fun, idx) { var result = fun.call(_this, event); if (result) stack.unshift.apply(stack, _toConsumableArray(stack.splice(idx, 1))); return result; }); } else { stack.forEach(function (fun) { return fun.call(_this, event); }); } } }]); return GraphEvent; }(); export { GraphEvent as default };