@@ -3,16 +3,13 @@ import { Directive, EmbeddedViewRef, Input, OnDestroy, TemplateRef, ViewContaine
33import { InternalVirtualRef , TableRow , VirtualContext , VirtualIndex } from '../interfaces/table-builder.external' ;
44import { detectChanges } from '../operators/detect-changes' ;
55
6- @Directive ( {
7- selector : '[virtualFor][virtualForOf]'
8- } )
6+ @Directive ( { selector : '[virtualFor][virtualForOf]' } )
97export class VirtualForDirective implements OnDestroy {
108 @Input ( ) public virtualForDiffIndexes : number [ ] = [ ] ;
11- @Input ( ) public virtualForBufferOffset : number | null = null ;
129 private cache : Map < number , InternalVirtualRef > = new Map ( ) ;
1310 private _source : TableRow [ ] = [ ] ;
1411 private _indexes : VirtualIndex [ ] = [ ] ;
15- private createFrameId : number ;
12+ private readonly createFrameId : number ;
1613 private removeFrameId : number ;
1714 private dirty : boolean = false ;
1815
@@ -48,13 +45,7 @@ export class VirtualForDirective implements OnDestroy {
4845 }
4946
5047 private createNewNodes ( indexes : VirtualIndex [ ] ) : void {
51- indexes . forEach ( ( index : VirtualIndex ) : void => {
52- if ( this . virtualBufferIsOverloadOrNull ) {
53- this . createEmbeddedViewByIndex ( index ) ;
54- } else {
55- this . createFrameId = window . requestAnimationFrame ( ( ) : void => this . createEmbeddedViewByIndex ( index ) ) ;
56- }
57- } ) ;
48+ ( indexes || [ ] ) . forEach ( ( index : VirtualIndex ) : void => this . createEmbeddedViewByIndex ( index ) ) ;
5849 }
5950
6051 private createEmbeddedView ( row : TableRow , index : VirtualIndex ) : void {
@@ -91,18 +82,10 @@ export class VirtualForDirective implements OnDestroy {
9182 }
9283
9384 this . virtualForDiffIndexes . forEach ( ( index : number ) : void => {
94- if ( this . virtualBufferIsOverloadOrNull ) {
95- this . removeEmbeddedViewByIndex ( index ) ;
96- } else {
97- this . removeFrameId = window . requestAnimationFrame ( ( ) : void => this . removeEmbeddedViewByIndex ( index ) ) ;
98- }
85+ this . removeFrameId = window . requestAnimationFrame ( ( ) : void => this . removeEmbeddedViewByIndex ( index ) ) ;
9986 } ) ;
10087 }
10188
102- private get virtualBufferIsOverloadOrNull ( ) : boolean {
103- return this . virtualForBufferOffset < 0 || ! Number . isInteger ( this . virtualForBufferOffset ) ;
104- }
105-
10689 private removeEmbeddedViewByIndex ( index : number ) : void {
10790 const ref : InternalVirtualRef | undefined = this . cache . get ( index ) ;
10891 if ( ref ) {
0 commit comments