From 02acfe739da2b2a6c19720b4baf0dac39c216575 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 8 Dec 2021 11:44:30 +0800 Subject: [PATCH] refactor(mp): improve render props --- packages/uni-mp-alipay/dist/uni.mp.esm.js | 8 ++------ packages/uni-mp-vue/dist/vue.runtime.esm.js | 6 ++++-- packages/uni-mp-vue/lib/vue.runtime.esm.js | 2 ++ packages/uni-mp-vue/src/helpers/renderProps.ts | 13 ++++++++++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index 51dba1cd2..45f5062dd 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -149,8 +149,7 @@ function createEmitFn(oldEmit, ctx) { } } { - const vnode = this.$.vnode; - const props = vnode && vnode.props; + const props = scope.props; if (props && props[`on${capitalize(event)}`]) { return; } @@ -756,11 +755,8 @@ function triggerEvent(type, detail) { if (!handler) { return; } - const eventOpts = this.props['data-event-opts']; const target = { - dataset: { - eventOpts, - }, + dataset: {}, }; handler({ type: customize(type), diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index f273ff3ea..b23fdfe5d 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -4749,6 +4749,8 @@ function renderComponentRoot(instance) { instance.$ei = 0; // props pruneComponentPropsCache(uid); + instance.__counter = + instance.__counter === 0 ? 1 : 0; let result; const prev = setCurrentRenderingInstance(instance); try { @@ -5076,10 +5078,10 @@ function initApp(app) { const propsCaches = Object.create(null); function renderProps(props) { - const { uid } = getCurrentInstance(); + const { uid, __counter } = getCurrentInstance(); const propsId = (propsCaches[uid] || (propsCaches[uid] = [])).push(guardReactiveProps(props)) - 1; // 强制每次更新 - return uid + ',' + propsId + ',' + Math.random(); + return uid + ',' + propsId + ',' + __counter; } function pruneComponentPropsCache(uid) { delete propsCaches[uid]; diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index 167f95ffc..563b3307b 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -4749,6 +4749,8 @@ function renderComponentRoot(instance) { instance.$ei = 0; // props pruneComponentPropsCache(uid); + instance.__counter = + instance.__counter === 0 ? 1 : 0; let result; const prev = setCurrentRenderingInstance(instance); try { diff --git a/packages/uni-mp-vue/src/helpers/renderProps.ts b/packages/uni-mp-vue/src/helpers/renderProps.ts index 64b2bb9eb..d18b42cd4 100644 --- a/packages/uni-mp-vue/src/helpers/renderProps.ts +++ b/packages/uni-mp-vue/src/helpers/renderProps.ts @@ -1,15 +1,22 @@ -import { getCurrentInstance, guardReactiveProps } from 'vue' +import { + ComponentInternalInstance, + getCurrentInstance, + guardReactiveProps, +} from 'vue' const propsCaches: Record[]> = Object.create(null) export function renderProps(props: Data) { - const { uid } = getCurrentInstance()! + const { uid, __counter } = + getCurrentInstance()! as ComponentInternalInstance & { + __counter: number + } const propsId = (propsCaches[uid] || (propsCaches[uid] = [])).push( guardReactiveProps(props)! ) - 1 // 强制每次更新 - return uid + ',' + propsId + ',' + Math.random() + return uid + ',' + propsId + ',' + __counter } export function pruneComponentPropsCache(uid: number) { -- GitLab