|
@@ -1,38 +0,0 @@
|
|
|
-
|
|
|
|
|
-// utils/render-bus.js
|
|
|
|
|
-class RenderEventBus {
|
|
|
|
|
- constructor() {
|
|
|
|
|
- this.listeners = {}
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 注册监听
|
|
|
|
|
- $on(event, callback) {
|
|
|
|
|
- if (!this.listeners[event]) {
|
|
|
|
|
- this.listeners[event] = []
|
|
|
|
|
- }
|
|
|
|
|
- this.listeners[event].push(callback)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 触发事件
|
|
|
|
|
- $emit(event, data) {
|
|
|
|
|
- if (this.listeners[event]) {
|
|
|
|
|
- this.listeners[event].forEach(callback => {
|
|
|
|
|
- callback(data)
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 移除监听
|
|
|
|
|
- $off(event, callback) {
|
|
|
|
|
- if (this.listeners[event]) {
|
|
|
|
|
- const index = this.listeners[event].indexOf(callback)
|
|
|
|
|
- if (index > -1) {
|
|
|
|
|
- this.listeners[event].splice(index, 1)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const MyRenderEventBus = new RenderEventBus();
|
|
|
|
|
-
|
|
|
|
|
-export {MyRenderEventBus};
|
|
|