@mpxjs/core 2.9.69-beta.5 → 2.9.69-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.69-beta.5",
3
+ "version": "2.9.69-beta.7",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -122,9 +122,10 @@ function extractObservers (options) {
122
122
  Object.keys(props).forEach(key => {
123
123
  const prop = props[key]
124
124
  if (prop && prop.observer) {
125
+ let callback = prop.observer
126
+ delete prop.observer
125
127
  mergeWatch(key, {
126
128
  handler (...rest) {
127
- let callback = prop.observer
128
129
  if (typeof callback === 'string') {
129
130
  callback = this[callback]
130
131
  }
package/src/core/proxy.js CHANGED
@@ -1,4 +1,4 @@
1
- import { reactive } from '../observer/reactive'
1
+ import { reactive, defineReactive } from '../observer/reactive'
2
2
  import { ReactiveEffect, pauseTracking, resetTracking } from '../observer/effect'
3
3
  import { effectScope } from '../platform/export/index'
4
4
  import { watch } from '../observer/watch'
@@ -111,7 +111,7 @@ export default class MpxProxy {
111
111
  this.uid = uid++
112
112
  this.name = options.name || ''
113
113
  this.options = options
114
- this.ignoreReactivePattern = this.options.options?.ignoreReactivePattern
114
+ this.shallowReactivePattern = this.options.options?.shallowReactivePattern
115
115
  // beforeCreate -> created -> mounted -> unmounted
116
116
  this.state = BEFORECREATE
117
117
  this.ignoreProxyMap = makeMap(Mpx.config.ignoreProxyWhiteList)
@@ -145,10 +145,12 @@ export default class MpxProxy {
145
145
  this.initApi()
146
146
  }
147
147
 
148
- processIgnoreReactive (obj) {
149
- if (this.ignoreReactivePattern && isObject(obj)) {
148
+ processShallowReactive (obj) {
149
+ if (this.shallowReactivePattern && isObject(obj)) {
150
150
  Object.keys(obj).forEach((key) => {
151
- if (this.ignoreReactivePattern.test(key)) {
151
+ if (this.shallowReactivePattern.test(key)) {
152
+ // 命中shallowReactivePattern的属性将其设置为 shallowReactive
153
+ defineReactive(obj, key, obj[key], true)
152
154
  Object.defineProperty(obj, key, {
153
155
  enumerable: true,
154
156
  // set configurable to false to skip defineReactive
@@ -290,10 +292,10 @@ export default class MpxProxy {
290
292
  if (isReact) {
291
293
  // react模式下props内部对象透传无需深clone,依赖对象深层的数据响应触发子组件更新
292
294
  this.props = this.target.__getProps()
293
- reactive(this.processIgnoreReactive(this.props))
295
+ reactive(this.processShallowReactive(this.props))
294
296
  } else {
295
297
  this.props = diffAndCloneA(this.target.__getProps(this.options)).clone
296
- reactive(this.processIgnoreReactive(this.props))
298
+ reactive(this.processShallowReactive(this.props))
297
299
  }
298
300
  proxy(this.target, this.props, undefined, false, this.createProxyConflictHandler('props'))
299
301
  }
@@ -333,7 +335,7 @@ export default class MpxProxy {
333
335
  if (isFunction(dataFn)) {
334
336
  Object.assign(this.data, callWithErrorHandling(dataFn.bind(this.target), this, 'data function'))
335
337
  }
336
- reactive(this.processIgnoreReactive(this.data))
338
+ reactive(this.processShallowReactive(this.data))
337
339
  proxy(this.target, this.data, undefined, false, this.createProxyConflictHandler('data'))
338
340
  this.collectLocalKeys(this.data)
339
341
  }
@@ -514,7 +516,7 @@ export default class MpxProxy {
514
516
  if (hasOwn(renderData, key)) {
515
517
  const data = renderData[key]
516
518
  const firstKey = getFirstKey(key)
517
- if (!this.localKeysMap[firstKey] || (this.ignoreReactivePattern && this.ignoreReactivePattern.test(firstKey))) {
519
+ if (!this.localKeysMap[firstKey]) {
518
520
  continue
519
521
  }
520
522
  // 外部clone,用于只需要clone的场景
@@ -23,13 +23,11 @@ function transformProperties (properties) {
23
23
  } else {
24
24
  newFiled = Object.assign({}, rawFiled)
25
25
  }
26
- const rawObserver = rawFiled?.observer
27
26
  newFiled.observer = function (value, oldValue) {
28
27
  if (this.__mpxProxy) {
29
28
  this[key] = value
30
29
  this.__mpxProxy.propsUpdated()
31
30
  }
32
- rawObserver && rawObserver.call(this, value, oldValue)
33
31
  }
34
32
  newProps[key] = newFiled
35
33
  })