Skip to content

Commit

Permalink
feat: ignoreReactivePattern 修改为 shallowReactivePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mackwang committed Jan 14, 2025
1 parent 5432414 commit 28e6c9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/core/mergeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'))
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 28e6c9a

Please sign in to comment.