@@ -402,9 +402,12 @@ class Component extends Base {
402
402
}
403
403
404
404
/**
405
- * @member {String[]} childUpdateCache=[]
405
+ * If an update() gets called while a parent is updating, we store the id & distance of the
406
+ * requesting component inside the childUpdateCache of the parent, to get resolved once the update is done.
407
+ * e.g. childUpdateCache = {'neo-grid-view-1': {distance: 1, resolve: fn}}
408
+ * @member {Object} childUpdateCache={}
406
409
*/
407
- childUpdateCache = [ ]
410
+ childUpdateCache = { }
408
411
/**
409
412
* Stores the updateDepth while an update is running to enable checks for parent update collisions
410
413
* @member {Number|null} currentUpdateDepth=null
@@ -1954,18 +1957,7 @@ class Component extends Base {
1954
1957
console . warn ( 'vdom parent update conflict with:' , parent , 'for:' , me )
1955
1958
}
1956
1959
1957
- // If our update gets prevented, ensure that the next parent updateDepth
1958
- // includes our own updateDepth
1959
- if ( parent . updateDepth !== - 1 ) {
1960
- if ( me . updateDepth === - 1 ) {
1961
- parent . updateDepth = - 1
1962
- } else {
1963
- // Since updateDepth is 1-based, we need to subtract 1 level
1964
- parent . updateDepth = parent . updateDepth + distance + me . updateDepth - 1
1965
- }
1966
- }
1967
-
1968
- NeoArray . add ( parent . childUpdateCache , me . id ) ;
1960
+ parent . childUpdateCache [ me . id ] = { distance, resolve} ;
1969
1961
1970
1962
// Adding the resolve fn to its own cache, since the parent will trigger
1971
1963
// a new update() directly on this cmp
@@ -2346,22 +2338,46 @@ class Component extends Base {
2346
2338
* @protected
2347
2339
*/
2348
2340
resolveVdomUpdate ( resolve ) {
2349
- let me = this ;
2341
+ let me = this ,
2342
+ hasChildUpdateCache = ! Neo . isEmpty ( me . childUpdateCache ) ,
2343
+ component ;
2350
2344
2351
2345
me . doResolveUpdateCache ( ) ;
2352
2346
2353
2347
resolve ?. ( ) ;
2354
2348
2355
2349
if ( me . needsVdomUpdate ) {
2356
- // if a new update is scheduled, we can clear the cache => these updates are included
2357
- me . childUpdateCache = [ ] ;
2350
+ if ( hasChildUpdateCache ) {
2351
+ Object . entries ( me . childUpdateCache ) . forEach ( ( [ key , value ] ) => {
2352
+ component = Neo . getComponent ( key ) ;
2353
+
2354
+ // The component might already got destroyed
2355
+ if ( component ) {
2356
+ // Pass callbacks to the resolver cache => getting executed once the following update is done
2357
+ value . resolve && NeoArray . add ( me . resolveUpdateCache , value . resolve ) ;
2358
+
2359
+ // Adjust the updateDepth to include the depth of all merged child updates
2360
+ if ( me . updateDepth !== - 1 ) {
2361
+ if ( component . updateDepth === - 1 ) {
2362
+ me . updateDepth = - 1
2363
+ } else {
2364
+ // Since updateDepth is 1-based, we need to subtract 1 level
2365
+ me . updateDepth = me . updateDepth + value . distance + component . updateDepth - 1
2366
+ }
2367
+ }
2368
+ }
2369
+ } ) ;
2370
+
2371
+ me . childUpdateCache = { }
2372
+ }
2358
2373
2359
2374
me . update ( )
2360
- } else if ( me . childUpdateCache ) {
2361
- [ ...me . childUpdateCache ] . forEach ( id => {
2362
- Neo . getComponent ( id ) ?. update ( ) ;
2363
- NeoArray . remove ( me . childUpdateCache , id )
2364
- } )
2375
+ } else if ( hasChildUpdateCache ) {
2376
+ Object . keys ( me . childUpdateCache ) . forEach ( key => {
2377
+ Neo . getComponent ( key ) ?. update ( )
2378
+ } ) ;
2379
+
2380
+ me . childUpdateCache = { }
2365
2381
}
2366
2382
}
2367
2383
0 commit comments