index.js 828 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
import Vue from 'vue'

const Emitter = new Vue()

export const on = Emitter.$on.bind(Emitter)
export const off = Emitter.$off.bind(Emitter)
export const once = Emitter.$once.bind(Emitter)
export const emit = Emitter.$emit.bind(Emitter)

export {
  invokeCallbackHandler
}
  from 'uni-helpers/api'

export function subscribe (event, callback) {
  return on('view.' + event, callback)
}

export function unsubscribe (event, callback) {
  return off('view.' + event, callback)
}

export function subscribeHandler (event, args, pageId) {
fxy060608's avatar
fxy060608 已提交
24
  if (process.env.NODE_ENV !== 'production') {
fxy060608's avatar
fxy060608 已提交
25
    console.log(`[subscribeHandler][${Date.now()}]:${event}, ${JSON.stringify(args)}, ${pageId}`)
fxy060608's avatar
fxy060608 已提交
26
  }
fxy060608's avatar
fxy060608 已提交
27 28 29 30 31 32
  return emit('view.' + event, args, pageId)
}

export {
  publishHandler
}
fxy060608's avatar
fxy060608 已提交
33
  from 'uni-platform/service/bridge'