From 68d23f0d8ece5de78fdfc33b32577387fce810ed Mon Sep 17 00:00:00 2001 From: qiang Date: Sun, 8 Aug 2021 15:32:54 +0800 Subject: [PATCH] fix(mp-vue3): scopedSlotsCompiler augmented --- packages/uni-mp-alipay/dist/uni.mp.esm.js | 51 +++++++++++++++++++ packages/uni-mp-baidu/dist/uni.mp.esm.js | 51 +++++++++++++++++++ packages/uni-mp-kuaishou/dist/uni.mp.esm.js | 55 ++++++++++++++++++++- packages/uni-mp-qq/dist/uni.mp.esm.js | 51 +++++++++++++++++++ packages/uni-mp-toutiao/dist/uni.mp.esm.js | 51 +++++++++++++++++++ packages/uni-mp-weixin/dist/uni.mp.esm.js | 51 +++++++++++++++++++ 6 files changed, 308 insertions(+), 2 deletions(-) diff --git a/packages/uni-mp-alipay/dist/uni.mp.esm.js b/packages/uni-mp-alipay/dist/uni.mp.esm.js index 29e6a327c..3f22d2561 100644 --- a/packages/uni-mp-alipay/dist/uni.mp.esm.js +++ b/packages/uni-mp-alipay/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, isArray, extend, hyphenate, isObject, hasOwn, toNumber, capitalize, isFunction, NOOP, EMPTY_OBJ, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -391,6 +392,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -440,6 +444,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index 28c53ea2e..20a90cbce 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -419,6 +420,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -465,6 +469,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ diff --git a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js index ac16bd244..b1d3f9776 100644 --- a/packages/uni-mp-kuaishou/dist/uni.mp.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -419,6 +420,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -465,6 +469,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ @@ -1179,7 +1230,7 @@ function fixSetDataStart(mpInstance) { mpInstance.__fixInitData = function () { this.setData = setData; const fn = () => { - setDataArgs.forEach(args => { + setDataArgs.forEach((args) => { setData.apply(this, args); }); }; @@ -1219,7 +1270,7 @@ function parse(componentOptions) { }; } var parseComponentOptions = extend({}, baseParseOptions, { - parse + parse, }); const createComponent = initCreateComponent(parseComponentOptions); diff --git a/packages/uni-mp-qq/dist/uni.mp.esm.js b/packages/uni-mp-qq/dist/uni.mp.esm.js index 2387513ad..05f436120 100644 --- a/packages/uni-mp-qq/dist/uni.mp.esm.js +++ b/packages/uni-mp-qq/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -419,6 +420,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -465,6 +469,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ diff --git a/packages/uni-mp-toutiao/dist/uni.mp.esm.js b/packages/uni-mp-toutiao/dist/uni.mp.esm.js index 95f25dfa0..fa129fc15 100644 --- a/packages/uni-mp-toutiao/dist/uni.mp.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -419,6 +420,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -465,6 +469,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ diff --git a/packages/uni-mp-weixin/dist/uni.mp.esm.js b/packages/uni-mp-weixin/dist/uni.mp.esm.js index e2744e4c4..161e4e768 100644 --- a/packages/uni-mp-weixin/dist/uni.mp.esm.js +++ b/packages/uni-mp-weixin/dist/uni.mp.esm.js @@ -1,4 +1,5 @@ import { isPlainObject, hasOwn, isArray, extend, hyphenate, isObject, toNumber, isFunction, NOOP, camelize } from '@vue/shared'; +import { onUnmounted } from 'vue'; const encode = encodeURIComponent; function stringifyQuery(obj, encodeStr = encode) { @@ -365,6 +366,9 @@ function initBaseInstance(instance, options) { } function initComponentInstance(instance, options) { initBaseInstance(instance, options); + { + initScopedSlotsParams(instance); + } const ctx = instance.ctx; MP_METHODS.forEach((method) => { ctx[method] = function (...args) { @@ -411,6 +415,53 @@ function callHook(name, args) { } const hooks = this.$[name]; return hooks && invokeArrayFns(hooks, args); +} +const center = {}; +const parents = {}; +function initScopedSlotsParams(instance) { + const ctx = instance.ctx; + ctx.$hasScopedSlotsParams = function (vueId) { + const has = center[vueId]; + if (!has) { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + return has; + }; + ctx.$getScopedSlotsParams = function (vueId, name, key) { + const data = center[vueId]; + if (data) { + const object = data[name] || {}; + return key ? object[key] : object; + } + else { + parents[vueId] = this; + onUnmounted(() => { + delete parents[vueId]; + }, instance); + } + }; + ctx.$setScopedSlotsParams = function (name, value) { + const vueIds = instance.attrs.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } + } + }; + onUnmounted(function () { + const propsData = instance.attrs; + const vueId = propsData && propsData.vueId; + if (vueId) { + delete center[vueId]; + delete parents[vueId]; + } + }, instance); } const PAGE_HOOKS = [ -- GitLab