UNPKG

t-comm

Version:

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

58 lines (53 loc) 1.63 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var eBus_eBus = require('./e-bus.js'); require('@babel/runtime/helpers/classCallCheck'); require('@babel/runtime/helpers/createClass'); var globalEBus = new eBus_eBus.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 eBus_eBus.EventBus(); app.config.globalProperties.$ebus = eBus; return [app, eBus]; }; exports.globalEBus = globalEBus; exports.initDiffVue3EBus = initDiffVue3EBus; exports.initGlobalVue3EBus = initGlobalVue3EBus;