Skip to content

Commit deaf001

Browse files
committed
refactor(*): removing redundant implementation
1 parent 503bc3c commit deaf001

File tree

5 files changed

+6
-24
lines changed

5 files changed

+6
-24
lines changed

projects/igniteui-angular/migrations/common/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export const parseFile = (parser: HtmlParser, host: Tree, filePath: string, enco
188188

189189
export const findElementNodes = (root: Node[], tag: string | string[]): Node[] => {
190190
const tags = new Set(Array.isArray(tag) ? tag : [tag]);
191-
return flatten(Array.isArray(root) ? root : [root])
191+
return (Array.isArray(root) ? root : [root]).flat()
192192
.filter((node: Element) => tags.has(node.name));
193193
};
194194

@@ -232,7 +232,7 @@ export const flatten = (list: Node[]) => {
232232
r.push(node);
233233

234234
if (isElement(node)) {
235-
r = r.concat(flatten((node as Element).children));
235+
r = r.concat((node as Element).children.flat());
236236
}
237237
}
238238
return r;

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -375,22 +375,6 @@ export class PlatformUtil {
375375
}
376376
}
377377

378-
/**
379-
* @hidden
380-
*/
381-
export const flatten = (arr: any[]) => {
382-
let result = [];
383-
384-
arr.forEach(el => {
385-
result.push(el);
386-
if (el.children) {
387-
const children = Array.isArray(el.children) ? el.children : el.children.toArray();
388-
result = result.concat(flatten(children));
389-
}
390-
});
391-
return result;
392-
};
393-
394378
export interface CancelableEventArgs {
395379
/**
396380
* Provides the ability to cancel the event.

projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { takeUntil } from 'rxjs/operators';
1313

1414
import { IgxColumnComponent } from './column.component';
15-
import { flatten } from '../../core/utils';
1615
import { CellType, ColumnType, IgxColumnTemplateContext } from '../common/grid.interface';
1716

1817
/* blazorElement */
@@ -351,7 +350,7 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
351350

352351
/** @hidden @internal **/
353352
public override get allChildren(): IgxColumnComponent[] {
354-
return flatten(this.children.toArray());
353+
return this.children.toArray().flat();
355354
}
356355
/**
357356
* Returns a boolean indicating if the column is a `ColumnGroup`.

projects/igniteui-angular/src/lib/grids/headers/grid-header-row.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ViewChildren,
1212
booleanAttribute
1313
} from '@angular/core';
14-
import { flatten, trackByIdentity } from '../../core/utils';
14+
import { trackByIdentity } from '../../core/utils';
1515
import { IgxGridForOfDirective } from '../../directives/for-of/for_of.directive';
1616
import { ColumnType, GridType, IgxHeadSelectorTemplateContext } from '../common/grid.interface';
1717
import { IgxGridFilteringCellComponent } from '../filtering/base/grid-filtering-cell.component';
@@ -80,7 +80,7 @@ export class IgxGridHeaderRowComponent implements DoCheck {
8080
* @hidden @internal
8181
*/
8282
public get groups(): IgxGridHeaderGroupComponent[] {
83-
return flatten(this._groups?.toArray() ?? []);
83+
return (this._groups?.toArray() ?? []).flat();
8484
}
8585

8686
/** Header components in the header row. */

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import { IgxGridDragSelectDirective } from '../selection/drag-select.directive';
6666
import { IgxGridBodyDirective } from '../grid.common';
6767
import { IgxGridHeaderRowComponent } from '../headers/grid-header-row.component';
6868
import { IgxActionStripToken } from '../../action-strip/token';
69-
import { flatten } from '../../core/utils';
7069
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
7170

7271
let NEXT_ID = 0;
@@ -1269,7 +1268,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
12691268
let fields = [];
12701269
let childEntities;
12711270
if (!rowIsland.autoGenerate) {
1272-
fields = flatten(rowIsland.childColumns.toArray()).filter(col => col.field)
1271+
fields = rowIsland.childColumns.toArray().flat().filter(col => col.field)
12731272
.map(f => ({ field: f.field, dataType: f.dataType })) as FieldType[];
12741273
} else if (firstRowData) {
12751274
const rowIslandFields = Object.keys(firstRowData).map(key => {

0 commit comments

Comments
 (0)