@@ -397,6 +397,25 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
397397 return this . scrollComponent . size > parseInt ( this . igxForContainerSize , 10 ) ;
398398 }
399399
400+ private get embeddedViewNodes ( ) {
401+ const result = new Array ( this . _embeddedViews . length ) ;
402+ for ( let i = 0 ; i < this . _embeddedViews . length ; i ++ ) {
403+ const view = this . _embeddedViews [ i ] ;
404+ for ( const node of view . rootNodes ) {
405+ if ( node . nodeType === Node . ELEMENT_NODE ) {
406+ result [ i ] = node ;
407+ break ;
408+ } else {
409+ const nextElem = node . nextElementSibling ;
410+ if ( nextElem ) {
411+ result [ i ] = nextElem ;
412+ }
413+ }
414+ }
415+ }
416+ return result ;
417+ }
418+
400419 /**
401420 * @hidden
402421 */
@@ -773,8 +792,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
773792 */
774793 public isIndexOutsideView ( index : number ) {
775794 const targetNode = index >= this . state . startIndex && index <= this . state . startIndex + this . state . chunkSize ?
776- this . _embeddedViews . map ( view =>
777- view . rootNodes . find ( node => node . nodeType === Node . ELEMENT_NODE ) || view . rootNodes [ 0 ] . nextElementSibling ) [ index - this . state . startIndex ] : null ;
795+ this . embeddedViewNodes [ index - this . state . startIndex ] : null ;
778796 const rowHeight = this . getSizeAt ( index ) ;
779797 const containerSize = parseInt ( this . igxForContainerSize , 10 ) ;
780798 const containerOffset = - ( this . scrollPosition - this . sizesCache [ this . state . startIndex ] ) ;
@@ -793,8 +811,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
793811 const diffs = [ ] ;
794812 let totalDiff = 0 ;
795813 const l = this . _embeddedViews . length ;
796- const rNodes = this . _embeddedViews . map ( view =>
797- view . rootNodes . find ( node => node . nodeType === Node . ELEMENT_NODE ) || view . rootNodes [ 0 ] . nextElementSibling ) ;
814+ const rNodes = this . embeddedViewNodes ;
798815 for ( let i = 0 ; i < l ; i ++ ) {
799816 const rNode = rNodes [ i ] ;
800817 if ( rNode ) {
@@ -1209,15 +1226,15 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
12091226 let size = 0 ;
12101227 const dimension = this . igxForSizePropName || 'height' ;
12111228 let i = 0 ;
1212- this . sizesCache = [ ] ;
1213- this . individualSizeCache = [ ] ;
1214- this . sizesCache . push ( 0 ) ;
12151229 const count = this . isRemote ? this . totalItemCount : items . length ;
1230+ this . sizesCache = new Array ( count + 1 ) ;
1231+ this . sizesCache [ 0 ] = 0 ;
1232+ this . individualSizeCache = new Array ( count ) ;
12161233 for ( i ; i < count ; i ++ ) {
12171234 size = this . _getItemSize ( items [ i ] , dimension ) ;
1218- this . individualSizeCache . push ( size ) ;
1235+ this . individualSizeCache [ i ] = size ;
12191236 totalSize += size ;
1220- this . sizesCache . push ( totalSize ) ;
1237+ this . sizesCache [ i + 1 ] = totalSize ;
12211238 }
12221239 return totalSize ;
12231240 }
@@ -1717,15 +1734,15 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec
17171734 let totalSize = 0 ;
17181735 let size = 0 ;
17191736 let i = 0 ;
1720- this . sizesCache = [ ] ;
1721- this . individualSizeCache = [ ] ;
1722- this . sizesCache . push ( 0 ) ;
17231737 const count = this . isRemote ? this . totalItemCount : items . length ;
1738+ this . sizesCache = new Array ( count + 1 ) ;
1739+ this . sizesCache [ 0 ] = 0 ;
1740+ this . individualSizeCache = new Array ( count ) ;
17241741 for ( i ; i < count ; i ++ ) {
17251742 size = this . getItemSize ( items [ i ] ) ;
1726- this . individualSizeCache . push ( size ) ;
1743+ this . individualSizeCache [ i ] = size ;
17271744 totalSize += size ;
1728- this . sizesCache . push ( totalSize ) ;
1745+ this . sizesCache [ i + 1 ] = totalSize ;
17291746 }
17301747 return totalSize ;
17311748 }
0 commit comments