@@ -11,7 +11,6 @@ export class VirtualForDirective implements OnDestroy {
1111 @Input ( ) public virtualForBufferOffset : number | null = null ;
1212 private cache : Map < number , InternalVirtualRef > = new Map ( ) ;
1313 private _source : TableRow [ ] = [ ] ;
14- // noinspection JSMismatchedCollectionQueryUpdate
1514 private _indexes : VirtualIndex [ ] = [ ] ;
1615 private createFrameId : number ;
1716 private removeFrameId : number ;
@@ -35,19 +34,23 @@ export class VirtualForDirective implements OnDestroy {
3534
3635 this . _indexes = indexes ;
3736 this . removeOldNodes ( ) ;
38- this . createNewNodes ( indexes ) ;
37+ this . createNewNodes ( this . _indexes ) ;
38+ }
39+
40+ private get sourceRef ( ) : TableRow [ ] {
41+ return this . _source || [ ] ;
3942 }
4043
4144 public ngOnDestroy ( ) : void {
42- this . view . clear ( ) ;
4345 window . cancelAnimationFrame ( this . createFrameId ) ;
4446 window . cancelAnimationFrame ( this . removeFrameId ) ;
47+ this . view . clear ( ) ;
4548 }
4649
4750 private createNewNodes ( indexes : VirtualIndex [ ] ) : void {
4851 indexes . forEach (
4952 ( index : VirtualIndex ) : void => {
50- if ( this . virtualForBufferOffset < 0 ) {
53+ if ( this . virtualBufferIsOverloadOrNull ) {
5154 this . createEmbeddedViewByIndex ( index ) ;
5255 } else {
5356 this . createFrameId = window . requestAnimationFrame (
@@ -70,7 +73,7 @@ export class VirtualForDirective implements OnDestroy {
7073 }
7174
7275 private createEmbeddedViewByIndex ( index : VirtualIndex ) : void {
73- const row : TableRow = this . _source [ index . position ] ;
76+ const row : TableRow = this . sourceRef [ index . position ] ;
7477 const virtualRef : InternalVirtualRef = this . cache . get ( index . position ) ;
7578
7679 if ( virtualRef ) {
@@ -93,7 +96,7 @@ export class VirtualForDirective implements OnDestroy {
9396
9497 this . virtualForDiffIndexes . forEach (
9598 ( index : number ) : void => {
96- if ( this . virtualForBufferOffset < 0 ) {
99+ if ( this . virtualBufferIsOverloadOrNull ) {
97100 this . removeEmbeddedViewByIndex ( index ) ;
98101 } else {
99102 this . removeFrameId = window . requestAnimationFrame (
@@ -104,6 +107,10 @@ export class VirtualForDirective implements OnDestroy {
104107 ) ;
105108 }
106109
110+ private get virtualBufferIsOverloadOrNull ( ) : boolean {
111+ return this . virtualForBufferOffset < 0 || ! Number . isInteger ( this . virtualForBufferOffset ) ;
112+ }
113+
107114 private removeEmbeddedViewByIndex ( index : number ) : void {
108115 const ref : InternalVirtualRef | undefined = this . cache . get ( index ) ;
109116 if ( ref ) {
0 commit comments