diff --git a/packages/core/src/core/mergeOptions.js b/packages/core/src/core/mergeOptions.js index e89414a01..dab3f1742 100644 --- a/packages/core/src/core/mergeOptions.js +++ b/packages/core/src/core/mergeOptions.js @@ -122,9 +122,10 @@ function extractObservers (options) { Object.keys(props).forEach(key => { const prop = props[key] if (prop && prop.observer) { + let callback = prop.observer + delete prop.observer mergeWatch(key, { handler (...rest) { - let callback = prop.observer if (typeof callback === 'string') { callback = this[callback] } diff --git a/packages/core/src/core/proxy.js b/packages/core/src/core/proxy.js index 78162e10b..15ff6719c 100644 --- a/packages/core/src/core/proxy.js +++ b/packages/core/src/core/proxy.js @@ -111,7 +111,7 @@ export default class MpxProxy { this.uid = uid++ this.name = options.name || '' this.options = options - this.ignoreReactivePattern = this.options.options?.ignoreReactivePattern + this.shallowReactivePattern = this.options.options?.shallowReactivePattern // beforeCreate -> created -> mounted -> unmounted this.state = BEFORECREATE this.ignoreProxyMap = makeMap(Mpx.config.ignoreProxyWhiteList) @@ -145,11 +145,11 @@ export default class MpxProxy { this.initApi() } - processIgnoreReactive (obj) { - if (this.ignoreReactivePattern && isObject(obj)) { + processShallowReactive (obj) { + if (this.shallowReactivePattern && isObject(obj)) { Object.keys(obj).forEach((key) => { - if (this.ignoreReactivePattern.test(key)) { - // 命中ignoreReactivePattern的属性将其设置为 shallowReactive + if (this.shallowReactivePattern.test(key)) { + // 命中shallowReactivePattern的属性将其设置为 shallowReactive defineReactive(obj, key, obj[key], true) Object.defineProperty(obj, key, { enumerable: true, @@ -292,10 +292,10 @@ export default class MpxProxy { if (isReact) { // react模式下props内部对象透传无需深clone,依赖对象深层的数据响应触发子组件更新 this.props = this.target.__getProps() - reactive(this.processIgnoreReactive(this.props)) + reactive(this.processShallowReactive(this.props)) } else { this.props = diffAndCloneA(this.target.__getProps(this.options)).clone - reactive(this.processIgnoreReactive(this.props)) + reactive(this.processShallowReactive(this.props)) } proxy(this.target, this.props, undefined, false, this.createProxyConflictHandler('props')) } @@ -335,7 +335,7 @@ export default class MpxProxy { if (isFunction(dataFn)) { Object.assign(this.data, callWithErrorHandling(dataFn.bind(this.target), this, 'data function')) } - reactive(this.processIgnoreReactive(this.data)) + reactive(this.processShallowReactive(this.data)) proxy(this.target, this.data, undefined, false, this.createProxyConflictHandler('data')) this.collectLocalKeys(this.data) }