@@ -148,15 +148,13 @@ export class Prop implements IProp, IPropParent {
148148
149149 @obx . shallow private _items : IProp [ ] | null = null ;
150150
151- @obx . shallow private _maps : Map < string | number , IProp > | null = null ;
152-
153151 /**
154- * 作为 _maps 的一层缓存机制 ,主要是复用部分已存在的 Prop,保持响应式关系,比如:
152+ * 作为一层缓存机制 ,主要是复用部分已存在的 Prop,保持响应式关系,比如:
155153 * 当前 Prop#_value 值为 { a: 1 },当调用 setValue({ a: 2 }) 时,所有原来的子 Prop 均被销毁,
156154 * 导致假如外部有 mobx reaction(常见于 observer),此时响应式链路会被打断,
157155 * 因为 reaction 监听的是原 Prop(a) 的 _value,而不是新 Prop(a) 的 _value。
158156 */
159- private _prevMaps : Map < string | number , IProp > | null = null ;
157+ @ obx . shallow private _maps : Map < string | number , IProp > | null = null ;
160158
161159 /**
162160 * 构造 items 属性,同时构造 maps 属性
@@ -171,8 +169,8 @@ export class Prop implements IProp, IPropParent {
171169 data . forEach ( ( item : any , idx : number ) => {
172170 items = items || [ ] ;
173171 let prop ;
174- if ( this . _prevMaps ?. has ( idx . toString ( ) ) ) {
175- prop = this . _prevMaps . get ( idx . toString ( ) ) ! ;
172+ if ( this . _maps ?. has ( idx . toString ( ) ) ) {
173+ prop = this . _maps . get ( idx . toString ( ) ) ! ;
176174 prop . setValue ( item ) ;
177175 } else {
178176 prop = new Prop ( this , item , idx ) ;
@@ -187,8 +185,8 @@ export class Prop implements IProp, IPropParent {
187185 const keys = Object . keys ( data ) ;
188186 for ( const key of keys ) {
189187 let prop : IProp ;
190- if ( this . _prevMaps ?. has ( key ) ) {
191- prop = this . _prevMaps . get ( key ) ! ;
188+ if ( this . _maps ?. has ( key ) ) {
189+ prop = this . _maps . get ( key ) ! ;
192190 prop . setValue ( data [ key ] ) ;
193191 } else {
194192 prop = new Prop ( this , data [ key ] , key ) ;
@@ -419,8 +417,6 @@ export class Prop implements IProp, IPropParent {
419417 items . forEach ( ( prop ) => prop . purge ( ) ) ;
420418 }
421419 this . _items = null ;
422- this . _prevMaps = this . _maps ;
423- this . _maps = null ;
424420 if ( this . _type !== 'slot' && this . _slotNode ) {
425421 this . _slotNode . remove ( ) ;
426422 this . _slotNode = undefined ;
0 commit comments