提交 25cea862 编写于 作者: fxy060608's avatar fxy060608

fix(mp): support $children

上级 087bc446
......@@ -197,8 +197,8 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
}
};
effects.forEach(run);
}
}
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
.map(key => Symbol[key])
......@@ -363,8 +363,8 @@ const shallowReactiveHandlers = extend({}, mutableHandlers, {
// retain the reactivity of the normal readonly object.
const shallowReadonlyHandlers = extend({}, readonlyHandlers, {
get: shallowReadonlyGet
});
});
const toReactive = (value) => isObject(value) ? reactive(value) : value;
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
const toShallow = (value) => value;
......@@ -639,8 +639,8 @@ function checkIdentityKeys(target, has, key) {
`Avoid differentiating between the raw and reactive versions ` +
`of an object and only use the reactive version if possible.`);
}
}
}
const reactiveMap = new WeakMap();
const shallowReactiveMap = new WeakMap();
const readonlyMap = new WeakMap();
......@@ -740,8 +740,8 @@ function toRaw(observed) {
function markRaw(value) {
def(value, "__v_skip" /* SKIP */, true);
return value;
}
}
const convert = (val) => isObject(val) ? reactive(val) : val;
function isRef(r) {
return Boolean(r && r.__v_isRef === true);
......@@ -845,8 +845,8 @@ function toRef(object, key) {
return isRef(object[key])
? object[key]
: new ObjectRefImpl(object, key);
}
}
class ComputedRefImpl {
constructor(getter, _setter, isReadonly) {
this._setter = _setter;
......@@ -893,8 +893,8 @@ function computed(getterOrOptions) {
setter = getterOrOptions.set;
}
return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
}
}
const stack = [];
function pushWarningContext(vnode) {
stack.push(vnode);
......@@ -1007,8 +1007,8 @@ function formatProp(key, value, raw) {
value = toRaw(value);
return raw ? value : [`${key}=`, value];
}
}
}
const ErrorTypeStrings = {
["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
["c" /* CREATED */]: 'created hook',
......@@ -1117,8 +1117,8 @@ function logError(err, type, contextVNode, throwInDev = true) {
// recover in prod to reduce the impact on end-user
console.error(err);
}
}
}
let isFlushing = false;
let isFlushPending = false;
// fixed by xxxxxx
......@@ -1303,8 +1303,8 @@ function checkRecursiveUpdates(seen, fn) {
seen.set(fn, count + 1);
}
}
}
}
function emit(instance, event, ...rawArgs) {
const props = instance.vnode.props || EMPTY_OBJ;
if ((process.env.NODE_ENV !== 'production')) {
......@@ -1423,21 +1423,21 @@ function isEmitListener(options, key) {
return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
hasOwn(options, hyphenate(key)) ||
hasOwn(options, key));
}
}
let isRenderingCompiledSlot = 0;
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
/**
* mark the current rendering instance for asset resolution (e.g.
* resolveComponent, resolveDirective) during render
*/
let currentRenderingInstance = null;
let currentScopeId = null;
let currentScopeId = null;
function markAttrsAccessed() {
}
}
function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
isSSR = false) {
const props = {};
......@@ -1756,8 +1756,8 @@ function isExplicable(type) {
*/
function isBoolean(...args) {
return args.some(elem => elem.toLowerCase() === 'boolean');
}
}
function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) {
const hooks = target[type] || (target[type] = []);
......@@ -1810,8 +1810,8 @@ const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
const onErrorCaptured = (hook, target = currentInstance) => {
injectHook("ec" /* ERROR_CAPTURED */, hook, target);
};
};
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
......@@ -2015,8 +2015,8 @@ function traverse(value, seen = new Set()) {
}
}
return value;
}
}
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
function onActivated(hook, target) {
registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
......@@ -2063,15 +2063,15 @@ function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
onUnmounted(() => {
remove(keepAliveRoot[type], injected);
}, target);
}
}
/**
Runtime helper for applying directives to a vnode. Example usage:
const comp = resolveComponent('comp')
const foo = resolveDirective('foo')
const bar = resolveDirective('bar')
return withDirectives(h(comp), [
[foo, this.x],
[bar, this.y]
......@@ -2091,8 +2091,8 @@ function withDirectives(vnode, directives) {
(process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
return vnode;
}
}
}
function createAppContext() {
return {
app: null,
......@@ -2219,17 +2219,17 @@ function createAppAPI() {
});
return app;
};
}
}
// implementation, close to no-op
function defineComponent(options) {
return isFunction(options) ? { setup: options, name: options.name } : options;
}
const queuePostRenderEffect = queuePostFlushCb;
const isTeleport = (type) => type.__isTeleport;
}
const queuePostRenderEffect = queuePostFlushCb;
const isTeleport = (type) => type.__isTeleport;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
const NULL_DYNAMIC_COMPONENT = Symbol();
......@@ -2279,8 +2279,8 @@ function resolve(registry, name) {
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
}
}
const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
......@@ -2568,8 +2568,8 @@ function mergeProps(...args) {
}
}
return ret;
}
}
function provide(key, value) {
if (!currentInstance) {
if ((process.env.NODE_ENV !== 'production')) {
......@@ -2618,8 +2618,8 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) {
else if ((process.env.NODE_ENV !== 'production')) {
warn(`inject() can only be used inside setup() or functional components.`);
}
}
}
function createDuplicateChecker() {
const cache = Object.create(null);
return (type, key) => {
......@@ -3027,8 +3027,8 @@ function mergeOptions(to, from, instance) {
to[key] = from[key];
}
}
}
}
/**
* #2437 In Vue 3, functional components do not have a public instance proxy but
* they exist in the internal parent chain. For code that relies on traversing
......@@ -3055,8 +3055,29 @@ const publicPropertiesMap = extend(Object.create(null), {
$options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
$forceUpdate: i => () => queueJob(i.update),
// $nextTick: i => nextTick.bind(i.proxy!), // fixed by xxxxxx
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP),
// compat
$children: getCompatChildren
});
function getCompatChildren(instance) {
const root = instance.subTree;
const children = [];
if (root) {
walk(root, children);
}
return children;
}
function walk(vnode, children) {
if (vnode.component) {
children.push(vnode.component.proxy);
}
else if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
const vnodes = vnode.children;
for (let i = 0; i < vnodes.length; i++) {
walk(vnodes[i], children);
}
}
}
const PublicInstanceProxyHandlers = {
get({ _: instance }, key) {
const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
......@@ -3290,8 +3311,8 @@ function exposeSetupStateOnRenderContext(instance) {
set: NOOP
});
});
}
}
const emptyAppContext = createAppContext();
let uid$2 = 0;
function createComponentInstance(vnode, parent, suspense) {
......@@ -3607,14 +3628,14 @@ function formatComponentName(instance, Component, isRoot = false) {
}
function isClassComponent(value) {
return isFunction(value) && '__vccOpts' in value;
}
}
function computed$1(getterOrOptions) {
const c = computed(getterOrOptions);
recordInstanceBoundEffect(c.effect);
return c;
}
}
// implementation
function defineProps() {
if ((process.env.NODE_ENV !== 'production')) {
......@@ -3632,11 +3653,11 @@ function defineEmit() {
`compiled away and passing it at runtime has no effect.`);
}
return null;
}
}
// Core API ------------------------------------------------------------------
const version = "3.0.9";
const version = "3.0.9";
// import deepCopy from './deepCopy'
/**
* https://raw.githubusercontent.com/Tencent/westore/master/packages/westore/utils/diff.js
......@@ -3747,8 +3768,8 @@ function _diff(current, pre, path, result) {
}
function setResult(result, k, v) {
result[k] = v; //deepCopy(v)
}
}
function hasComponentEffect(instance) {
return queue.includes(instance.update);
}
......@@ -3815,8 +3836,8 @@ function nextTick$1(instance, fn) {
return new Promise(resolve => {
_resolve = resolve;
});
}
}
function getMPInstanceData(instance, keys) {
const data = instance.data;
const ret = Object.create(null);
......@@ -3893,14 +3914,14 @@ function patch(instance) {
flushCallbacks(instance);
}
}
}
}
function initAppConfig(appConfig) {
appConfig.globalProperties.$nextTick = function $nextTick(fn) {
return nextTick$1(this.$, fn);
};
}
}
function onApplyOptions(options, instance, publicThis) {
instance.appContext.config.globalProperties.$applyOptions(options, instance, publicThis);
const computedOptions = options.computed;
......@@ -3916,8 +3937,8 @@ function onApplyOptions(options, instance, publicThis) {
}
// remove
delete instance.ctx.$onApplyOptions;
}
}
var MPType;
(function (MPType) {
MPType["APP"] = "app";
......@@ -4046,8 +4067,8 @@ function createVueApp(rootComponent, rootProps = null) {
warn(`Cannot unmount an app.`);
};
return app;
}
}
function withModifiers() { }
function createVNode$1() { }
......
import { EMPTY_OBJ, isArray, isMap, isIntegerKey, isSymbol, extend, hasOwn, isObject, hasChanged, makeMap, capitalize, toRawType, def, isFunction, NOOP, isString, isPromise, toHandlerKey, toNumber, hyphenate, camelize, isOn, isReservedProp, EMPTY_ARR, remove, isSet, NO, normalizeClass, normalizeStyle, isGloballyWhitelisted, toTypeString, invokeArrayFns } from '@vue/shared';
export { camelize } from '@vue/shared';
import { EMPTY_OBJ, isArray, isMap, isIntegerKey, isSymbol, extend, hasOwn, isObject, hasChanged, makeMap, capitalize, toRawType, def, isFunction, NOOP, isString, isPromise, toHandlerKey, toNumber, hyphenate, camelize, isOn, isReservedProp, EMPTY_ARR, remove, isSet, NO, normalizeClass, normalizeStyle, isGloballyWhitelisted, toTypeString, invokeArrayFns } from '@vue/shared';
export { camelize } from '@vue/shared';
const targetMap = new WeakMap();
const effectStack = [];
let activeEffect;
......@@ -188,8 +188,8 @@ function trigger(target, type, key, newValue, oldValue, oldTarget) {
}
};
effects.forEach(run);
}
}
const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
const builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol)
.map(key => Symbol[key])
......@@ -354,8 +354,8 @@ const shallowReactiveHandlers = extend({}, mutableHandlers, {
// retain the reactivity of the normal readonly object.
const shallowReadonlyHandlers = extend({}, readonlyHandlers, {
get: shallowReadonlyGet
});
});
const toReactive = (value) => isObject(value) ? reactive(value) : value;
const toReadonly = (value) => isObject(value) ? readonly(value) : value;
const toShallow = (value) => value;
......@@ -630,8 +630,8 @@ function checkIdentityKeys(target, has, key) {
`Avoid differentiating between the raw and reactive versions ` +
`of an object and only use the reactive version if possible.`);
}
}
}
const reactiveMap = new WeakMap();
const shallowReactiveMap = new WeakMap();
const readonlyMap = new WeakMap();
......@@ -731,8 +731,8 @@ function toRaw(observed) {
function markRaw(value) {
def(value, "__v_skip" /* SKIP */, true);
return value;
}
}
const convert = (val) => isObject(val) ? reactive(val) : val;
function isRef(r) {
return Boolean(r && r.__v_isRef === true);
......@@ -836,8 +836,8 @@ function toRef(object, key) {
return isRef(object[key])
? object[key]
: new ObjectRefImpl(object, key);
}
}
class ComputedRefImpl {
constructor(getter, _setter, isReadonly) {
this._setter = _setter;
......@@ -884,8 +884,8 @@ function computed(getterOrOptions) {
setter = getterOrOptions.set;
}
return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set);
}
}
const stack = [];
function pushWarningContext(vnode) {
stack.push(vnode);
......@@ -998,8 +998,8 @@ function formatProp(key, value, raw) {
value = toRaw(value);
return raw ? value : [`${key}=`, value];
}
}
}
const ErrorTypeStrings = {
["bc" /* BEFORE_CREATE */]: 'beforeCreate hook',
["c" /* CREATED */]: 'created hook',
......@@ -1108,8 +1108,8 @@ function logError(err, type, contextVNode, throwInDev = true) {
// recover in prod to reduce the impact on end-user
console.error(err);
}
}
}
let isFlushing = false;
let isFlushPending = false;
// fixed by xxxxxx
......@@ -1294,8 +1294,8 @@ function checkRecursiveUpdates(seen, fn) {
seen.set(fn, count + 1);
}
}
}
}
function emit(instance, event, ...rawArgs) {
const props = instance.vnode.props || EMPTY_OBJ;
if ((process.env.NODE_ENV !== 'production')) {
......@@ -1414,21 +1414,21 @@ function isEmitListener(options, key) {
return (hasOwn(options, key[0].toLowerCase() + key.slice(1)) ||
hasOwn(options, hyphenate(key)) ||
hasOwn(options, key));
}
}
let isRenderingCompiledSlot = 0;
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
const setCompiledSlotRendering = (n) => (isRenderingCompiledSlot += n);
/**
* mark the current rendering instance for asset resolution (e.g.
* resolveComponent, resolveDirective) during render
*/
let currentRenderingInstance = null;
let currentScopeId = null;
let currentScopeId = null;
function markAttrsAccessed() {
}
}
function initProps(instance, rawProps, isStateful, // result of bitwise flag comparison
isSSR = false) {
const props = {};
......@@ -1747,8 +1747,8 @@ function isExplicable(type) {
*/
function isBoolean(...args) {
return args.some(elem => elem.toLowerCase() === 'boolean');
}
}
function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) {
const hooks = target[type] || (target[type] = []);
......@@ -1801,8 +1801,8 @@ const onRenderTriggered = createHook("rtg" /* RENDER_TRIGGERED */);
const onRenderTracked = createHook("rtc" /* RENDER_TRACKED */);
const onErrorCaptured = (hook, target = currentInstance) => {
injectHook("ec" /* ERROR_CAPTURED */, hook, target);
};
};
// Simple effect.
function watchEffect(effect, options) {
return doWatch(effect, null, options);
......@@ -2006,8 +2006,8 @@ function traverse(value, seen = new Set()) {
}
}
return value;
}
}
const isKeepAlive = (vnode) => vnode.type.__isKeepAlive;
function onActivated(hook, target) {
registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);
......@@ -2054,15 +2054,15 @@ function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
onUnmounted(() => {
remove(keepAliveRoot[type], injected);
}, target);
}
}
/**
Runtime helper for applying directives to a vnode. Example usage:
const comp = resolveComponent('comp')
const foo = resolveDirective('foo')
const bar = resolveDirective('bar')
return withDirectives(h(comp), [
[foo, this.x],
[bar, this.y]
......@@ -2082,8 +2082,8 @@ function withDirectives(vnode, directives) {
(process.env.NODE_ENV !== 'production') && warn(`withDirectives can only be used inside render functions.`);
return vnode;
}
}
}
function createAppContext() {
return {
app: null,
......@@ -2210,17 +2210,17 @@ function createAppAPI() {
});
return app;
};
}
}
// implementation, close to no-op
function defineComponent(options) {
return isFunction(options) ? { setup: options, name: options.name } : options;
}
const queuePostRenderEffect = queuePostFlushCb;
const isTeleport = (type) => type.__isTeleport;
}
const queuePostRenderEffect = queuePostFlushCb;
const isTeleport = (type) => type.__isTeleport;
const COMPONENTS = 'components';
const DIRECTIVES = 'directives';
const NULL_DYNAMIC_COMPONENT = Symbol();
......@@ -2270,8 +2270,8 @@ function resolve(registry, name) {
(registry[name] ||
registry[camelize(name)] ||
registry[capitalize(camelize(name))]));
}
}
const Fragment = Symbol((process.env.NODE_ENV !== 'production') ? 'Fragment' : undefined);
const Text = Symbol((process.env.NODE_ENV !== 'production') ? 'Text' : undefined);
const Comment = Symbol((process.env.NODE_ENV !== 'production') ? 'Comment' : undefined);
......@@ -2559,8 +2559,8 @@ function mergeProps(...args) {
}
}
return ret;
}
}
function provide(key, value) {
if (!currentInstance) {
if ((process.env.NODE_ENV !== 'production')) {
......@@ -2609,8 +2609,8 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) {
else if ((process.env.NODE_ENV !== 'production')) {
warn(`inject() can only be used inside setup() or functional components.`);
}
}
}
function createDuplicateChecker() {
const cache = Object.create(null);
return (type, key) => {
......@@ -3018,8 +3018,8 @@ function mergeOptions(to, from, instance) {
to[key] = from[key];
}
}
}
}
/**
* #2437 In Vue 3, functional components do not have a public instance proxy but
* they exist in the internal parent chain. For code that relies on traversing
......@@ -3046,8 +3046,29 @@ const publicPropertiesMap = extend(Object.create(null), {
$options: i => (__VUE_OPTIONS_API__ ? resolveMergedOptions(i) : i.type),
$forceUpdate: i => () => queueJob(i.update),
// $nextTick: i => nextTick.bind(i.proxy!), // fixed by xxxxxx
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP)
$watch: i => (__VUE_OPTIONS_API__ ? instanceWatch.bind(i) : NOOP),
// compat
$children: getCompatChildren
});
function getCompatChildren(instance) {
const root = instance.subTree;
const children = [];
if (root) {
walk(root, children);
}
return children;
}
function walk(vnode, children) {
if (vnode.component) {
children.push(vnode.component.proxy);
}
else if (vnode.shapeFlag & 16 /* ARRAY_CHILDREN */) {
const vnodes = vnode.children;
for (let i = 0; i < vnodes.length; i++) {
walk(vnodes[i], children);
}
}
}
const PublicInstanceProxyHandlers = {
get({ _: instance }, key) {
const { ctx, setupState, data, props, accessCache, type, appContext } = instance;
......@@ -3281,8 +3302,8 @@ function exposeSetupStateOnRenderContext(instance) {
set: NOOP
});
});
}
}
const emptyAppContext = createAppContext();
let uid$2 = 0;
function createComponentInstance(vnode, parent, suspense) {
......@@ -3598,14 +3619,14 @@ function formatComponentName(instance, Component, isRoot = false) {
}
function isClassComponent(value) {
return isFunction(value) && '__vccOpts' in value;
}
}
function computed$1(getterOrOptions) {
const c = computed(getterOrOptions);
recordInstanceBoundEffect(c.effect);
return c;
}
}
// implementation
function defineProps() {
if ((process.env.NODE_ENV !== 'production')) {
......@@ -3623,11 +3644,11 @@ function defineEmit() {
`compiled away and passing it at runtime has no effect.`);
}
return null;
}
}
// Core API ------------------------------------------------------------------
const version = "3.0.9";
const version = "3.0.9";
// import deepCopy from './deepCopy'
/**
* https://raw.githubusercontent.com/Tencent/westore/master/packages/westore/utils/diff.js
......@@ -3738,8 +3759,8 @@ function _diff(current, pre, path, result) {
}
function setResult(result, k, v) {
result[k] = v; //deepCopy(v)
}
}
function hasComponentEffect(instance) {
return queue.includes(instance.update);
}
......@@ -3806,8 +3827,8 @@ function nextTick$1(instance, fn) {
return new Promise(resolve => {
_resolve = resolve;
});
}
}
function getMPInstanceData(instance, keys) {
const data = instance.data;
const ret = Object.create(null);
......@@ -3884,14 +3905,14 @@ function patch(instance) {
flushCallbacks(instance);
}
}
}
}
function initAppConfig(appConfig) {
appConfig.globalProperties.$nextTick = function $nextTick(fn) {
return nextTick$1(this.$, fn);
};
}
}
function onApplyOptions(options, instance, publicThis) {
instance.appContext.config.globalProperties.$applyOptions(options, instance, publicThis);
const computedOptions = options.computed;
......@@ -3907,8 +3928,8 @@ function onApplyOptions(options, instance, publicThis) {
}
// remove
delete instance.ctx.$onApplyOptions;
}
}
var MPType;
(function (MPType) {
MPType["APP"] = "app";
......@@ -4037,9 +4058,9 @@ function createVueApp(rootComponent, rootProps = null) {
warn(`Cannot unmount an app.`);
};
return app;
}
}
function withModifiers() { }
function createVNode$1() { }
export { callWithAsyncErrorHandling, callWithErrorHandling, computed$1 as computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmit, defineProps, getCurrentInstance, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, provide, reactive, readonly, ref, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, version, warn, watch, watchEffect, withDirectives, withModifiers };
function createVNode$1() { }
export { callWithAsyncErrorHandling, callWithErrorHandling, computed$1 as computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmit, defineProps, getCurrentInstance, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, provide, reactive, readonly, ref, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, version, warn, watch, watchEffect, withDirectives, withModifiers };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册