Skip to content

Commit

Permalink
support properties.observer
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Nov 1, 2024
1 parent 87e034d commit af3b9f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ export default class MpxProxy {
}

processIgnoreReactive (obj) {
if (isObject(obj) && this.ignoreReactivePattern) {
if (this.ignoreReactivePattern && isObject(obj)) {
Object.keys(obj).forEach((key) => {
if (this.ignoreReactivePattern.test(key)) {
Object.defineProperty(obj, key, {
enumerable: true,
// set configurable to false to skip defineReactive
configurable: false,
configurable: false
})
}
})
Expand Down Expand Up @@ -435,7 +435,7 @@ export default class MpxProxy {
if (hasOwn(renderData, key)) {
const data = renderData[key]
const firstKey = getFirstKey(key)
if (!this.localKeysMap[firstKey] || (this.ignoreReactivePattern && this.this.ignoreReactivePattern.test(firstKey))) {
if (!this.localKeysMap[firstKey] || (this.ignoreReactivePattern && this.ignoreReactivePattern.test(firstKey))) {
continue
}
// 外部clone,用于只需要clone的场景
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/platform/patch/wx/getDefaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ function transformProperties (properties) {
} else {
newFiled = Object.assign({}, rawFiled)
}
newFiled.observer = function (value) {
const rawObserver = rawFiled?.observer
newFiled.observer = function (value, oldValue) {
if (this.__mpxProxy) {
this[key] = value
this.__mpxProxy.propsUpdated()
}
rawObserver && rawObserver.call(this, value, oldValue)
}
newProps[key] = newFiled
})
Expand Down

0 comments on commit af3b9f2

Please sign in to comment.