From 5b29435ee5bf2a5780ff83b102f69617d117df33 Mon Sep 17 00:00:00 2001 From: xxxxxx Date: Sat, 9 Jan 2021 19:22:50 +0800 Subject: [PATCH] fix(mp-baidu): Page AOP --- src/platforms/mp-kuaishou/runtime/index.js | 45 +--------------------- src/platforms/mp-weixin/runtime/index.js | 3 +- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/src/platforms/mp-kuaishou/runtime/index.js b/src/platforms/mp-kuaishou/runtime/index.js index cb6abd39d..f304dc72a 100644 --- a/src/platforms/mp-kuaishou/runtime/index.js +++ b/src/platforms/mp-kuaishou/runtime/index.js @@ -1,44 +1 @@ -import { - 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) -} +import '../../mp-weixin/runtime/index' diff --git a/src/platforms/mp-weixin/runtime/index.js b/src/platforms/mp-weixin/runtime/index.js index 882e159c4..a88089ad5 100644 --- a/src/platforms/mp-weixin/runtime/index.js +++ b/src/platforms/mp-weixin/runtime/index.js @@ -42,8 +42,9 @@ Page = function (options = {}) { initHook('onLoad', options) return MPPage(options) } +Page.after = MPPage.after Component = function (options = {}) { initHook('created', options) return MPComponent(options) -} +} -- GitLab