@@ -3,7 +3,7 @@ import { createSelectorQuery } from '../../api/core/wxml/selector-query'
33import { createIntersectionObserver } from '../../api/core/wxml/intersection-observer'
44import message from '../../core/message'
55import runtime from '../../core/runtime'
6- import { addComputedData , filterData , filterInvokeObserver , invokeObserversOnce , isChildComponent , matchComponent , syncUpdateChildrenProps } from '../../core/utils'
6+ import { addComputedData , deepEqual , filterData , filterInvokeObserver , invokeObserversOnce , isChildComponent , matchComponent , syncUpdateChildrenProps } from '../../core/utils'
77
88// 组件生命周期
99const componentLifetimes = [ 'created' , 'attached' , 'ready' , 'moved' , 'detached' , 'error' ]
@@ -60,6 +60,7 @@ export class Component {
6060 // 保存子组件 properties 绑定关系(用于同步更新)
6161 // 格式:{ childModuleId: { childPropName: parentDataKey } }
6262 this . __childPropsBindings__ = { }
63+ this . __pendingSyncedProps__ = { }
6364 }
6465
6566 init ( ) {
@@ -461,33 +462,48 @@ export class Component {
461462 * 触发观察者函数
462463 * triggerObserver
463464 */
464- tO ( data , triggerObservers = true ) {
465+ tO ( data ) {
466+ const nextData = { }
467+ for ( const [ prop , val ] of Object . entries ( data ) ) {
468+ if (
469+ this . __pendingSyncedProps__
470+ && Object . hasOwn ( this . __pendingSyncedProps__ , prop )
471+ && deepEqual ( this . __pendingSyncedProps__ [ prop ] , val )
472+ ) {
473+ delete this . __pendingSyncedProps__ [ prop ]
474+ continue
475+ }
476+ nextData [ prop ] = val
477+ }
478+
479+ if ( Object . keys ( nextData ) . length === 0 ) {
480+ return
481+ }
482+
465483 // 收集需要执行的观察者函数
466484 const observersToExecute = [ ]
467485 const propertyObserversToExecute = [ ]
468486
469487 // 保存旧值并更新数据,收集观察者
470- for ( const [ prop , val ] of Object . entries ( data ) ) {
488+ for ( const [ prop , val ] of Object . entries ( nextData ) ) {
471489 // 保存旧值
472490 const oldVal = this . data [ prop ]
473491
474492 // 更新数据
475493 this . data [ prop ] = val
476494
477- if ( triggerObservers ) {
478- // 收集 observers
479- if ( this . __info__ . observers ) {
480- observersToExecute . push ( ( ) => filterInvokeObserver ( prop , this . __info__ . observers , data , this , oldVal ) )
481- }
482-
483- // 收集属性观察器
484- const observer = this . __info__ . properties ?. [ prop ] ?. observer
485- if ( isString ( observer ) ) {
486- propertyObserversToExecute . push ( ( ) => this [ observer ] ?. ( val , oldVal ) )
487- }
488- else if ( isFunction ( observer ) ) {
489- propertyObserversToExecute . push ( ( ) => observer . call ( this , val , oldVal ) )
490- }
495+ // 收集 observers
496+ if ( this . __info__ . observers ) {
497+ observersToExecute . push ( ( ) => filterInvokeObserver ( prop , this . __info__ . observers , this . data , this , oldVal ) )
498+ }
499+
500+ // 收集属性观察器
501+ const observer = this . __info__ . properties ?. [ prop ] ?. observer
502+ if ( isString ( observer ) ) {
503+ propertyObserversToExecute . push ( ( ) => this [ observer ] ?. ( val , oldVal ) )
504+ }
505+ else if ( isFunction ( observer ) ) {
506+ propertyObserversToExecute . push ( ( ) => observer . call ( this , val , oldVal ) )
491507 }
492508 }
493509
0 commit comments