提交 8154200e 编写于 作者: Q qiang

fix(mp): scopedSlotsCompiler augmented

上级 16962672
......@@ -157,6 +157,7 @@ declare namespace UniApp {
'mp-qq'?: PagesJsonPageStyle
'mp-toutiao'?: PagesJsonPageStyle
'mp-weixin'?: PagesJsonPageStyle
'mp-kuaishou'?: PagesJsonPageStyle
'quickapp-webview'?: PagesJsonPageStyle
'quickapp-webview-huawei'?: PagesJsonPageStyle
'quickapp-webview-union'?: PagesJsonPageStyle
......
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 = [
......
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 = [
......
......@@ -7,8 +7,11 @@ import {
isObject,
isPlainObject,
} from '@vue/shared'
import { ComponentPublicInstance, ComponentInternalInstance } from 'vue'
import {
ComponentPublicInstance,
ComponentInternalInstance,
onUnmounted,
} from 'vue'
import { getEventChannel } from '../../api/protocols/navigateTo'
import { MPComponentInstance } from '../component'
import { getClass, getStyle, getValue } from './utils'
......@@ -167,6 +170,16 @@ export function initComponentInstance(
options: CreateComponentOptions
) {
initBaseInstance(instance, options)
if (
__PLATFORM__ === 'mp-weixin' ||
__PLATFORM__ === 'mp-qq' ||
__PLATFORM__ === 'mp-toutiao' ||
__PLATFORM__ === 'mp-kuaishou' ||
__PLATFORM__ === 'mp-alipay' ||
__PLATFORM__ === 'mp-baidu'
) {
initScopedSlotsParams(instance)
}
const ctx = (instance as any).ctx
MP_METHODS.forEach((method) => {
......@@ -225,3 +238,58 @@ function callHook(this: ComponentPublicInstance, name: string, args?: unknown) {
const hooks = (this.$ as any)[name]
return hooks && invokeArrayFns(hooks, args)
}
const center: Record<string, any> = {}
const parents: Record<string, ComponentPublicInstance> = {}
function initScopedSlotsParams(instance: ComponentInternalInstance) {
const ctx = (instance as any).ctx
ctx.$hasScopedSlotsParams = function (vueId: string) {
const has = center[vueId]
if (!has) {
parents[vueId] = this
onUnmounted(() => {
delete parents[vueId]
}, instance)
}
return has
}
ctx.$getScopedSlotsParams = function (
vueId: string,
name: string,
key: string
) {
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: string, value: any) {
const vueIds = instance.attrs.vueId as string
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 as string)
if (vueId) {
delete center[vueId]
delete parents[vueId]
}
}, instance)
}
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);
......
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 = [
......
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 = [
......
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 = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册