UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

52 lines (49 loc) 1.46 kB
import { EventBus } from './e-bus.mjs'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; var globalEBus = new EventBus(); /** * 挂载统一的eBus,所有实例共用一个 * @param app Vue3 应用实例 * @example * ```ts * import { createApp } from 'vue'; * import App from './App.vue'; * * const app = createApp(App); * initGlobalVue3EBus(app); * * // 组件内:this.$ebus.emit('event-name', payload) * ``` */ var initGlobalVue3EBus = function initGlobalVue3EBus(app) { var _a; if (!((_a = app === null || app === void 0 ? void 0 : app.config) === null || _a === void 0 ? void 0 : _a.globalProperties)) { return app; } app.config.globalProperties.$ebus = globalEBus; return [app, globalEBus]; }; /** * 挂载唯一的eBus,不同实例用不同的 * @param app Vue3 应用实例 * @example * ```ts * import { createApp } from 'vue'; * import App from './App.vue'; * * const app = createApp(App); * const [_, eBus] = initDiffVue3EBus(app); * // 每个 app 实例拥有独立的 eBus * ``` */ var initDiffVue3EBus = function initDiffVue3EBus(app) { var _a; if (!((_a = app === null || app === void 0 ? void 0 : app.config) === null || _a === void 0 ? void 0 : _a.globalProperties)) { return app; } var eBus = new EventBus(); app.config.globalProperties.$ebus = eBus; return [app, eBus]; }; export { globalEBus, initDiffVue3EBus, initGlobalVue3EBus };