提交 5b29435e 编写于 作者: X xxxxxx

fix(mp-baidu): Page AOP

上级 e1b93ee2
import { import '../../mp-weixin/runtime/index'
cached,
camelize
} from 'uni-shared'
const MPPage = Page
const MPComponent = Component
const customizeRE = /:/g
const customize = cached((str) => {
return camelize(str.replace(customizeRE, '-'))
})
function initTriggerEvent (mpInstance) {
const oldTriggerEvent = mpInstance.triggerEvent
mpInstance.triggerEvent = function (event, ...args) {
return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
}
}
function initHook (name, options) {
const oldHook = options[name]
if (!oldHook) {
options[name] = function () {
initTriggerEvent(this)
}
} else {
options[name] = function (...args) {
initTriggerEvent(this)
return oldHook.apply(this, args)
}
}
}
Page = function (options = {}) {
initHook('onLoad', options)
return MPPage(options)
}
Component = function (options = {}) {
initHook('created', options)
return MPComponent(options)
}
...@@ -42,8 +42,9 @@ Page = function (options = {}) { ...@@ -42,8 +42,9 @@ Page = function (options = {}) {
initHook('onLoad', options) initHook('onLoad', options)
return MPPage(options) return MPPage(options)
} }
Page.after = MPPage.after
Component = function (options = {}) { Component = function (options = {}) {
initHook('created', options) initHook('created', options)
return MPComponent(options) return MPComponent(options)
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册