@@ -335,8 +335,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
335
335
this . _trackBy = val ;
336
336
}
337
337
338
- private _hasUpdate = false ;
339
-
340
338
constructor (
341
339
private _iterableDiffers : IterableDiffers ,
342
340
private _elementRef : ElementRef ,
@@ -356,7 +354,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
356
354
357
355
// wait for the content to be rendered and has readable dimensions
358
356
_content . readReady . subscribe ( ( ) => {
359
- this . readUpdate ( true , true ) ;
357
+ this . readUpdate ( true ) ;
360
358
361
359
if ( ! this . _scrollSub ) {
362
360
// listen for scroll events
@@ -370,19 +368,10 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
370
368
} ) ;
371
369
}
372
370
373
- readUpdate ( checkDataChanges : boolean , dimensionsUpdated : boolean ) {
371
+ readUpdate ( dimensionsUpdated : boolean ) {
374
372
if ( ! this . _records ) return ;
375
373
376
- if ( checkDataChanges && ! dimensionsUpdated ) {
377
- if ( isPresent ( this . _differ ) && ! isPresent ( this . _differ . diff ( this . _records ) ) ) {
378
- // no changes
379
- return ;
380
- }
381
- }
382
-
383
- console . debug ( `virtual-scroll, readUpdate, checkDataChanges: ${ checkDataChanges } , dimensionsUpdated: ${ dimensionsUpdated } ` ) ;
384
-
385
- this . _hasUpdate = true ;
374
+ console . debug ( `virtual-scroll, readUpdate, dimensionsUpdated: ${ dimensionsUpdated } ` ) ;
386
375
387
376
// reset everything
388
377
this . _cells . length = 0 ;
@@ -399,9 +388,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
399
388
}
400
389
401
390
writeUpdate ( ) {
402
- if ( ! this . _hasUpdate ) {
403
- return ;
404
- }
391
+ if ( ! this . _records ) return ;
405
392
406
393
console . debug ( `virtual-scroll, writeUpdate` ) ;
407
394
@@ -414,16 +401,20 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
414
401
415
402
// ******** DOM WRITE ****************
416
403
this . renderVirtual ( ) ;
404
+ }
417
405
418
- this . _hasUpdate = false ;
406
+ private _hasChanges ( ) {
407
+ return ( isPresent ( this . _records ) && isPresent ( this . _differ ) && isPresent ( this . _differ . diff ( this . _records ) ) ) ;
419
408
}
420
409
421
410
/**
422
411
* @private
423
412
*/
424
413
ngDoCheck ( ) {
425
- if ( this . _init ) {
426
- this . readUpdate ( true , false ) ;
414
+ if ( this . _init && this . _hasChanges ( ) ) {
415
+ // only continue if we've already initialized
416
+ // and if there actually are changes
417
+ this . readUpdate ( false ) ;
427
418
this . writeUpdate ( ) ;
428
419
}
429
420
}
@@ -444,13 +435,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
444
435
this . approxItemHeight = '40px' ;
445
436
console . warn ( 'Virtual Scroll: Please provide an "approxItemHeight" input to ensure proper virtual scroll rendering' ) ;
446
437
}
447
-
448
- // this.update(true);
449
-
450
- // this._platform.onResize(() => {
451
- // console.debug('VirtualScroll, onResize');
452
- // this.update(false);
453
- // });
454
438
}
455
439
}
456
440
0 commit comments