From 9cc69410c25685c9251606fc82b91f8fd157be27 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Fri, 22 Dec 2023 17:37:30 -0500 Subject: [PATCH] perf: prefer `.forEach` over `for...in` and `for...of` (#1281) --- packages/common/src/core/slickCore.ts | 17 ++- packages/common/src/core/slickDataview.ts | 26 ++-- packages/common/src/core/slickGrid.ts | 132 ++++++++++-------- .../extensions/slickCheckboxSelectColumn.ts | 10 +- .../src/extensions/slickRowSelectionModel.ts | 6 +- .../common/src/filters/nativeSelectFilter.ts | 8 +- .../common/src/services/collection.service.ts | 4 +- packages/common/src/services/domUtilities.ts | 4 +- .../common/src/services/extension.service.ts | 28 ++-- .../common/src/services/filter.service.ts | 38 ++--- packages/common/src/services/sort.service.ts | 12 +- .../common/src/services/treeData.service.ts | 4 +- packages/common/src/services/utilities.ts | 8 +- .../src/slick-composite-editor.component.ts | 8 +- packages/utils/src/domUtils.ts | 6 +- 15 files changed, 168 insertions(+), 143 deletions(-) diff --git a/packages/common/src/core/slickCore.ts b/packages/common/src/core/slickCore.ts index a2071fd80..d809a1fef 100644 --- a/packages/common/src/core/slickCore.ts +++ b/packages/common/src/core/slickCore.ts @@ -39,14 +39,11 @@ export class SlickEventData { // when we already have an event, we want to keep some of the event properties // looping through some props is the only way to keep and sync these properties to the returned EventData if (event) { - const eventProps = [ + [ 'altKey', 'ctrlKey', 'metaKey', 'shiftKey', 'key', 'keyCode', 'clientX', 'clientY', 'offsetX', 'offsetY', 'pageX', 'pageY', 'bubbles', 'type', 'which', 'x', 'y' - ]; - for (const key of eventProps) { - (this as any)[key] = event[key as keyof Event]; - } + ].forEach(key => (this as any)[key] = event[key as keyof Event]); } this.target = this.nativeEvent ? this.nativeEvent.target : undefined; } @@ -660,10 +657,12 @@ export class Utils { } public static applyDefaults(targetObj: any, srcObj: any) { - for (const key in srcObj) { - if (srcObj.hasOwnProperty(key) && !targetObj.hasOwnProperty(key)) { - targetObj[key] = srcObj[key]; - } + if (typeof srcObj === 'object') { + Object.keys(srcObj).forEach(key => { + if (srcObj.hasOwnProperty(key) && !targetObj.hasOwnProperty(key)) { + targetObj[key] = srcObj[key]; + } + }); } } diff --git a/packages/common/src/core/slickDataview.ts b/packages/common/src/core/slickDataview.ts index 6c74edebc..c35a859ec 100644 --- a/packages/common/src/core/slickDataview.ts +++ b/packages/common/src/core/slickDataview.ts @@ -1557,11 +1557,13 @@ export class SlickDataView implements CustomD const storeCellCssStyles = (hash: CssStyleHash) => { hashById = {}; - for (const row in hash) { - if (hash) { - const id = this.rows[row as any][this.idProperty as keyof TData]; - hashById[id] = hash[row]; - } + if (typeof hash === 'object') { + Object.keys(hash).forEach(row => { + if (hash) { + const id = this.rows[row as any][this.idProperty as keyof TData]; + hashById[id] = hash[row]; + } + }); } }; @@ -1570,18 +1572,16 @@ export class SlickDataView implements CustomD storeCellCssStyles(grid.getCellCssStyles(key)); const update = () => { - if (hashById) { + if (typeof hashById === 'object') { inHandler = true; this.ensureRowsByIdCache(); const newHash: CssStyleHash = {}; - for (const id in hashById) { - if (hashById) { - const row = this.rowsById?.[id]; - if (isDefined(row)) { - newHash[row as number] = hashById[id]; - } + Object.keys(hashById).forEach(id => { + const row = this.rowsById?.[id]; + if (isDefined(row)) { + newHash[row as number] = hashById[id]; } - } + }); grid.setCellCssStyles(key, newHash); inHandler = false; } diff --git a/packages/common/src/core/slickGrid.ts b/packages/common/src/core/slickGrid.ts index 7e4f53bf5..2751574b2 100644 --- a/packages/common/src/core/slickGrid.ts +++ b/packages/common/src/core/slickGrid.ts @@ -898,7 +898,7 @@ export class SlickGrid = Column, O e /** handles "display:none" on container or container parents, related to issue: https://github.com/6pac/SlickGrid/issues/568 */ cacheCssForHiddenInit() { this._hiddenParents = Utils.parents(this._container, ':hidden') as HTMLElement[]; - for (const el of this._hiddenParents) { + this._hiddenParents.forEach(el => { const old: Partial = {}; for (const name in this.cssShow) { if (this.cssShow) { @@ -907,20 +907,22 @@ export class SlickGrid = Column, O e } } this.oldProps.push(old); - } + }); } restoreCssFromHiddenInit() { // finish handle display:none on container or container parents // - put values back the way they were let i = 0; - for (const el of this._hiddenParents) { - const old = this.oldProps[i++]; - for (const name in this.cssShow) { - if (this.cssShow) { - el.style[name as CSSStyleDeclarationWritable] = (old as any)[name]; + if (this._hiddenParents) { + this._hiddenParents.forEach(el => { + const old = this.oldProps[i++]; + for (const name in this.cssShow) { + if (this.cssShow) { + el.style[name as CSSStyleDeclarationWritable] = (old as any)[name]; + } } - } + }); } } @@ -2384,9 +2386,9 @@ export class SlickGrid = Column, O e const sheet = this._style.sheet; if (sheet) { - for (const rule of rules) { + rules.forEach(rule => { sheet.insertRule(rule); - } + }); for (let i = 0; i < this.columns.length; i++) { if (!this.columns[i] || this.columns[i].hidden) { continue; } @@ -3485,11 +3487,11 @@ export class SlickGrid = Column, O e cellDiv.setAttribute('title', toolTipText); if (m.hasOwnProperty('cellAttrs') && m.cellAttrs instanceof Object) { - for (const key in m.cellAttrs) { + Object.keys(m.cellAttrs).forEach(key => { if (m.cellAttrs.hasOwnProperty(key)) { cellDiv.setAttribute(key, m.cellAttrs[key]); } - } + }); } // if there is a corresponding row (if not, this is the Add New row or this data hasn't been loaded yet) @@ -3546,12 +3548,18 @@ export class SlickGrid = Column, O e if (this.currentEditor) { this.makeActiveCellNormal(); } - for (const row in this.rowsCache) { - if (this.rowsCache) { - this.removeRowFromCache(+row); - } + + if (typeof this.rowsCache === 'object') { + Object.keys(this.rowsCache).forEach(row => { + if (this.rowsCache) { + this.removeRowFromCache(+row); + } + }); + } + + if (this._options.enableAsyncPostRenderCleanup) { + this.startPostProcessingCleanup(); } - if (this._options.enableAsyncPostRenderCleanup) { this.startPostProcessingCleanup(); } } /** @@ -3588,16 +3596,18 @@ export class SlickGrid = Column, O e this.postProcessgroupId++; // store and detach node for later async cleanup - for (const columnIdx in postProcessedRow) { - if (postProcessedRow.hasOwnProperty(columnIdx)) { - this.postProcessedCleanupQueue.push({ - actionType: 'C', - groupId: this.postProcessgroupId, - node: cacheEntry.cellNodesByColumnIdx[+columnIdx], - columnIdx: +columnIdx, - rowIdx - }); - } + if (typeof postProcessedRow === 'object') { + Object.keys(postProcessedRow).forEach(columnIdx => { + if (postProcessedRow.hasOwnProperty(columnIdx)) { + this.postProcessedCleanupQueue.push({ + actionType: 'C', + groupId: this.postProcessgroupId, + node: cacheEntry.cellNodesByColumnIdx[+columnIdx], + columnIdx: +columnIdx, + rowIdx + }); + } + }); } if (!cacheEntry.rowNode) { @@ -3920,11 +3930,15 @@ export class SlickGrid = Column, O e // remove the rows that are now outside of the data range // this helps avoid redundant calls to .removeRow() when the size of the data decreased by thousands of rows const r1 = dataLength - 1; - for (const i in this.rowsCache) { - if (Number(i) > r1) { - this.removeRowFromCache(+i); - } + if (typeof this.rowsCache === 'object') { + Object.keys(this.rowsCache).forEach(row => { + const cachedRow = +row; + if (cachedRow > r1) { + this.removeRowFromCache(cachedRow); + } + }); } + if (this._options.enableAsyncPostRenderCleanup) { this.startPostProcessingCleanup(); } @@ -4306,10 +4320,12 @@ export class SlickGrid = Column, O e protected invalidatePostProcessingResults(row: number) { // change status of columns to be re-rendered - for (const columnIdx in this.postProcessedRows[row]) { - if (this.postProcessedRows[row].hasOwnProperty(columnIdx)) { - this.postProcessedRows[row][columnIdx] = 'C'; - } + if (typeof this.postProcessedRows[row] === 'object') { + Object.keys(this.postProcessedRows[row]).forEach(columnIdx => { + if (this.postProcessedRows[row].hasOwnProperty(columnIdx)) { + this.postProcessedRows[row][columnIdx] = 'C'; + } + }); } this.postProcessFromRow = Math.min(this.postProcessFromRow as number, row); this.postProcessToRow = Math.max(this.postProcessToRow as number, row); @@ -4317,11 +4333,11 @@ export class SlickGrid = Column, O e } protected updateRowPositions() { - for (const row in this.rowsCache) { - if (this.rowsCache) { + if (this.rowsCache && typeof this.rowsCache === 'object') { + Object.keys(this.rowsCache).forEach(row => { const rowNumber = row ? parseInt(row, 10) : 0; Utils.setStyleSize(this.rowsCache[rowNumber].rowNode![0], 'top', this.getRowTop(rowNumber)); - } + }); } } @@ -4631,33 +4647,35 @@ export class SlickGrid = Column, O e let columnId: number | string; let addedRowHash; let removedRowHash; - for (const row in this.rowsCache) { - if (this.rowsCache) { - removedRowHash = removedHash?.[row]; - addedRowHash = addedHash?.[row]; - - if (removedRowHash) { - for (columnId in removedRowHash) { - if (!addedRowHash || removedRowHash[columnId] !== addedRowHash[columnId]) { - node = this.getCellNode(+row, this.getColumnIndex(columnId)); - if (node) { - node.classList.remove(removedRowHash[columnId]); + if (typeof this.rowsCache === 'object') { + Object.keys(this.rowsCache).forEach(row => { + if (this.rowsCache) { + removedRowHash = removedHash?.[row]; + addedRowHash = addedHash?.[row]; + + if (removedRowHash) { + for (columnId in removedRowHash) { + if (!addedRowHash || removedRowHash[columnId] !== addedRowHash[columnId]) { + node = this.getCellNode(+row, this.getColumnIndex(columnId)); + if (node) { + node.classList.remove(removedRowHash[columnId]); + } } } } - } - if (addedRowHash) { - for (columnId in addedRowHash) { - if (!removedRowHash || removedRowHash[columnId] !== addedRowHash[columnId]) { - node = this.getCellNode(+row, this.getColumnIndex(columnId)); - if (node) { - node.classList.add(addedRowHash[columnId]); + if (addedRowHash) { + for (columnId in addedRowHash) { + if (!removedRowHash || removedRowHash[columnId] !== addedRowHash[columnId]) { + node = this.getCellNode(+row, this.getColumnIndex(columnId)); + if (node) { + node.classList.add(addedRowHash[columnId]); + } } } } } - } + }); } } diff --git a/packages/common/src/extensions/slickCheckboxSelectColumn.ts b/packages/common/src/extensions/slickCheckboxSelectColumn.ts index 20e848bbe..f8ce0fad6 100644 --- a/packages/common/src/extensions/slickCheckboxSelectColumn.ts +++ b/packages/common/src/extensions/slickCheckboxSelectColumn.ts @@ -492,10 +492,12 @@ export class SlickCheckboxSelectColumn { removeList.push(row); } } - for (const selectedRow in this._selectedRowsLookup) { - if (selectedRow !== undefined) { - this._grid.invalidateRow(+selectedRow); - } + if (typeof this._selectedRowsLookup === 'object') { + Object.keys(this._selectedRowsLookup).forEach(selectedRow => { + if (selectedRow !== undefined) { + this._grid.invalidateRow(+selectedRow); + } + }); } this._selectedRowsLookup = lookup; diff --git a/packages/common/src/extensions/slickRowSelectionModel.ts b/packages/common/src/extensions/slickRowSelectionModel.ts index 78de80059..6e2dadc3a 100644 --- a/packages/common/src/extensions/slickRowSelectionModel.ts +++ b/packages/common/src/extensions/slickRowSelectionModel.ts @@ -250,11 +250,9 @@ export class SlickRowSelectionModel implements SelectionModel { } protected rowsToRanges(rows: number[]) { - const ranges = []; + const ranges: SlickRange[] = []; const lastCell = this._grid.getColumns().length - 1; - for (const row of rows) { - ranges.push(new SlickRange(row, 0, row, lastCell)); - } + rows.forEach(row => ranges.push(new SlickRange(row, 0, row, lastCell))); return ranges; } } \ No newline at end of file diff --git a/packages/common/src/filters/nativeSelectFilter.ts b/packages/common/src/filters/nativeSelectFilter.ts index eb1d8ad27..ed67c794b 100644 --- a/packages/common/src/filters/nativeSelectFilter.ts +++ b/packages/common/src/filters/nativeSelectFilter.ts @@ -159,13 +159,13 @@ export class NativeSelectFilter implements Filter { // collection could be an Array of Strings OR Objects if (collection.every(x => typeof x === 'string')) { - for (const option of collection) { + collection.forEach(option => { selectElm.appendChild( createDomElement('option', { value: option, label: option, textContent: option }) ); - } + }); } else { - for (const option of collection) { + collection.forEach(option => { if (!option || (option[labelName] === undefined && option.labelKey === undefined)) { throw new Error(`A collection with value/label (or value/labelKey when using Locale) is required to populate the Native Select Filter list, for example:: { filter: model: Filters.select, collection: [ { value: '1', label: 'One' } ]')`); } @@ -176,7 +176,7 @@ export class NativeSelectFilter implements Filter { selectElm.appendChild( createDomElement('option', { value: option[valueName], textContent: textLabel }) ); - } + }); } return selectElm; diff --git a/packages/common/src/services/collection.service.ts b/packages/common/src/services/collection.service.ts index 5a3ec26c0..8c019da71 100644 --- a/packages/common/src/services/collection.service.ts +++ b/packages/common/src/services/collection.service.ts @@ -27,14 +27,14 @@ export class CollectionService { if (Array.isArray(filterByOptions)) { filteredCollection = (filterResultBy === FilterMultiplePassType.merge) ? [] : [...collection]; - for (const filter of filterByOptions) { + filterByOptions.forEach(filter => { if (filterResultBy === FilterMultiplePassType.merge) { const filteredPass = this.singleFilterCollection(collection, filter); filteredCollection = uniqueArray([...filteredCollection, ...filteredPass]); } else { filteredCollection = this.singleFilterCollection(filteredCollection, filter); } - } + }); } else { filteredCollection = this.singleFilterCollection(collection, filterByOptions); } diff --git a/packages/common/src/services/domUtilities.ts b/packages/common/src/services/domUtilities.ts index 4bf653f76..13d0efe56 100644 --- a/packages/common/src/services/domUtilities.ts +++ b/packages/common/src/services/domUtilities.ts @@ -45,7 +45,7 @@ export function buildMsSelectCollectionList(type: 'editor' | 'filter', collectio // collection could be an Array of Strings OR Objects if (Array.isArray(collection)) { if (collection.every((x: any) => typeof x === 'number' || typeof x === 'string')) { - for (const option of collection) { + collection.forEach(option => { const selectOption: OptionRowData = { text: option, value: option }; if (type === 'filter' && Array.isArray(searchTerms)) { selectOption.selected = (searchTerms.findIndex(term => term === option) >= 0); // when filter search term is found then select it in dropdown @@ -57,7 +57,7 @@ export function buildMsSelectCollectionList(type: 'editor' | 'filter', collectio if ((selectOption.selected && isMultiSelect) || (selectOption.selected && !isMultiSelect && option !== '')) { hasFoundSearchTerm = true; } - } + }); } else { // array of objects will require a label/value pair unless a customStructure is passed collection.forEach((option: SelectOption) => { diff --git a/packages/common/src/services/extension.service.ts b/packages/common/src/services/extension.service.ts index f2acda5c1..c49083c83 100644 --- a/packages/common/src/services/extension.service.ts +++ b/packages/common/src/services/extension.service.ts @@ -69,16 +69,22 @@ export class ExtensionService { this.sharedService.visibleColumns = []; // dispose of each control/plugin & reset the list - for (const extensionName of Object.keys(this._extensionList)) { - if (this._extensionList.hasOwnProperty(extensionName)) { - const extension = this._extensionList[extensionName as keyof Record>] as ExtensionModel; - if (extension?.instance?.dispose) { - extension.instance.dispose(); + if (typeof this._extensionList === 'object') { + const extensionNames = Object.keys(this._extensionList); + + // dispose each extension + extensionNames.forEach(extensionName => { + if (this._extensionList.hasOwnProperty(extensionName)) { + const extension = this._extensionList[extensionName as keyof Record>] as ExtensionModel; + if (typeof extension?.instance?.dispose === 'function') { + extension.instance.dispose(); + } } - } - } - for (const key of Object.keys(this._extensionList)) { - delete this._extensionList[key as keyof Record>]; + }); + // delete the extension from the _extensionList object + extensionNames.forEach(key => { + delete this._extensionList[key as keyof Record>]; + }); } this._cellMenuPlugin = null as any; this._cellExcelCopyManagerPlugin = null as any; @@ -470,11 +476,11 @@ export class ExtensionService { } if (Array.isArray(items)) { - for (const item of items) { + items.forEach(item => { if (item[inputKey]) { item[outputKey] = this.translaterService?.translate(item[inputKey]); } - } + }); } } } diff --git a/packages/common/src/services/filter.service.ts b/packages/common/src/services/filter.service.ts index cfd0e959b..e7fcc0565 100644 --- a/packages/common/src/services/filter.service.ts +++ b/packages/common/src/services/filter.service.ts @@ -561,32 +561,34 @@ export class FilterService { const filteredParents = new Map(); if (Array.isArray(inputItems)) { - for (const inputItem of inputItems) { + inputItems.forEach(inputItem => { (treeObj as any)[inputItem[primaryDataId]] = inputItem; // as the filtered data is then used again as each subsequent letter // we need to delete the .__used property, otherwise the logic below // in the while loop (which checks for parents) doesn't work delete (treeObj as any)[inputItem[primaryDataId]].__used; - } + }); // Step 1. prepare search filter by getting their parsed value(s), for example if it's a date filter then parse it to a Moment object // loop through all column filters once and get parsed filter search value then save a reference in the columnFilter itself // it is much more effective to do it outside and prior to Step 2 so that we don't re-parse search filter for no reason while checking every row - for (const columnId of Object.keys(columnFilters)) { - const columnFilter = columnFilters[columnId] as SearchColumnFilter; - const searchValues: SearchTerm[] = columnFilter?.searchTerms ? deepCopy(columnFilter.searchTerms) : []; - const inputSearchConditions = this.parseFormInputFilterConditions(searchValues, columnFilter); - - const columnDef = columnFilter.columnDef; - const fieldType = columnDef?.filter?.type ?? columnDef?.type ?? FieldType.string; - const parsedSearchTerms = getParsedSearchTermsByFieldType(inputSearchConditions.searchTerms, fieldType); // parsed term could be a single value or an array of values - if (parsedSearchTerms !== undefined) { - columnFilter.parsedSearchTerms = parsedSearchTerms; - } + if (typeof columnFilters === 'object') { + Object.keys(columnFilters).forEach(columnId => { + const columnFilter = columnFilters[columnId] as SearchColumnFilter; + const searchValues: SearchTerm[] = columnFilter?.searchTerms ? deepCopy(columnFilter.searchTerms) : []; + const inputSearchConditions = this.parseFormInputFilterConditions(searchValues, columnFilter); + + const columnDef = columnFilter.columnDef; + const fieldType = columnDef?.filter?.type ?? columnDef?.type ?? FieldType.string; + const parsedSearchTerms = getParsedSearchTermsByFieldType(inputSearchConditions.searchTerms, fieldType); // parsed term could be a single value or an array of values + if (parsedSearchTerms !== undefined) { + columnFilter.parsedSearchTerms = parsedSearchTerms; + } + }); } // Step 2. loop through every item data context to execute filter condition check - for (const item of inputItems) { + inputItems.forEach(item => { const hasChildren = item[hasChildrenPropName]; let matchFilter = true; // valid until proven otherwise @@ -652,7 +654,7 @@ export class FilterService { parent = (treeObj as any)[parent[parentPropName]] ?? false; } } - } + }); } this._isTreePresetExecuted = true; @@ -1238,7 +1240,7 @@ export class FilterService { } /** - * From a ColumnFilters object, extra only the basic filter details (columnId, operator & searchTerms) + * From a ColumnFilters object, extract only the basic filter details (columnId, operator & searchTerms) * @param {Object} columnFiltersObject - columnFilters object * @returns - basic details of a column filter */ @@ -1267,11 +1269,11 @@ export class FilterService { */ protected removeAllColumnFiltersProperties() { if (typeof this._columnFilters === 'object') { - for (const columnId in this._columnFilters) { + Object.keys(this._columnFilters).forEach(columnId => { if (columnId && this._columnFilters[columnId]) { delete this._columnFilters[columnId]; } - } + }); } } diff --git a/packages/common/src/services/sort.service.ts b/packages/common/src/services/sort.service.ts index 86babb561..76e119a73 100644 --- a/packages/common/src/services/sort.service.ts +++ b/packages/common/src/services/sort.service.ts @@ -440,9 +440,9 @@ export class SortService { if (emitSortChanged) { // update current sorters this._currentLocalSorters = []; - for (const sortCol of sortColumns) { + sortColumns.forEach(sortCol => { this._currentLocalSorters.push({ columnId: sortCol.columnId, direction: sortCol.sortAsc ? 'ASC' : 'DESC' }); - } + }); const emitterType = this._gridOptions?.backendServiceApi ? EmitterType.remote : EmitterType.local; this.emitSortChanged(emitterType); } @@ -512,9 +512,9 @@ export class SortService { sortTreeData(treeArray: any[], sortColumns: Array) { if (Array.isArray(sortColumns)) { - for (const sortColumn of sortColumns) { + sortColumns.forEach(sortColumn => { this.sortTreeChildren(treeArray, sortColumn, 0); - } + }); } } @@ -525,7 +525,7 @@ export class SortService { treeArray.sort((a: any, b: any) => this.sortComparer(sortColumn, a, b) ?? SortDirectionNumber.neutral); // when item has a child, we'll sort recursively - for (const item of treeArray) { + treeArray.forEach(item => { if (item) { const hasChildren = item.hasOwnProperty(childrenPropName) && Array.isArray(item[childrenPropName]); // when item has a child, we'll sort recursively @@ -535,7 +535,7 @@ export class SortService { treeLevel--; } } - } + }); } /** diff --git a/packages/common/src/services/treeData.service.ts b/packages/common/src/services/treeData.service.ts index 6857cdcf0..ae31ade62 100644 --- a/packages/common/src/services/treeData.service.ts +++ b/packages/common/src/services/treeData.service.ts @@ -180,7 +180,7 @@ export class TreeDataService { this.dataView.beginUpdate(true); // then we reapply only the ones that changed (provided as argument to the function) - for (const collapsedItem of treeToggledItems) { + treeToggledItems.forEach(collapsedItem => { const item = this.dataView.getItemById(collapsedItem.itemId); this.updateToggledItem(item, collapsedItem.isCollapsed); @@ -199,7 +199,7 @@ export class TreeDataService { type: collapsedItem.isCollapsed ? ToggleStateChangeType.toggleCollapse : ToggleStateChangeType.toggleExpand } as TreeToggleStateChange); } - } + }); // close the update transaction & call a refresh which will trigger a re-render with filters applied (including expand/collapse) this.dataView.endUpdate(); diff --git a/packages/common/src/services/utilities.ts b/packages/common/src/services/utilities.ts index c760c8ef6..b11c65895 100644 --- a/packages/common/src/services/utilities.ts +++ b/packages/common/src/services/utilities.ts @@ -70,7 +70,7 @@ export function addTreeLevelByMutation(treeArray: T[], options: { childrenPro const childrenPropName = (options?.childrenPropName ?? Constants.treeDataProperties.CHILDREN_PROP) as keyof T; if (Array.isArray(treeArray)) { - for (const item of treeArray) { + treeArray.forEach(item => { if (item) { if (Array.isArray(item[childrenPropName]) && (item[childrenPropName] as Array).length > 0) { treeLevel++; @@ -79,7 +79,7 @@ export function addTreeLevelByMutation(treeArray: T[], options: { childrenPro } (item as any)[options.levelPropName] = treeLevel; } - } + }); } } @@ -88,7 +88,7 @@ export function addTreeLevelAndAggregatorsByMutation(treeArray: T[], op const { aggregator } = options; if (Array.isArray(treeArray)) { - for (const item of treeArray) { + treeArray.forEach(item => { if (item) { const isParent = Array.isArray(item[childrenPropName]); @@ -105,7 +105,7 @@ export function addTreeLevelAndAggregatorsByMutation(treeArray: T[], op } (item as any)[options.levelPropName] = treeLevel; } - } + }); } } diff --git a/packages/composite-editor-component/src/slick-composite-editor.component.ts b/packages/composite-editor-component/src/slick-composite-editor.component.ts index 2d58d2331..d7a2e876d 100644 --- a/packages/composite-editor-component/src/slick-composite-editor.component.ts +++ b/packages/composite-editor-component/src/slick-composite-editor.component.ts @@ -560,7 +560,7 @@ export class SlickCompositeEditorComponent implements ExternalResource { // from the "lastCompositeEditor" object that we kept as reference, it contains all the changes inside the "formValues" property // we can loop through these changes and apply them on the selected row indexes - for (const itemProp in formValues) { + Object.keys(formValues).forEach(itemProp => { if (itemProp in formValues) { data.forEach((dataContext: any) => { if (itemProp in formValues && (this._options?.validateMassUpdateChange === undefined || this._options.validateMassUpdateChange(itemProp, dataContext, formValues) !== false)) { @@ -568,7 +568,7 @@ export class SlickCompositeEditorComponent implements ExternalResource { } }); } - } + }); // change the entire dataset with our updated dataset if (applyToDataview) { @@ -588,7 +588,7 @@ export class SlickCompositeEditorComponent implements ExternalResource { // from the "lastCompositeEditor" object that we kept as reference, it contains all the changes inside the "formValues" property // we can loop through these changes and apply them on the selected row indexes - for (const itemProp in formValues) { + Object.keys(formValues).forEach(itemProp => { if (itemProp in formValues) { selectedItems.forEach((dataContext: any) => { if (itemProp in formValues && (this._options?.validateMassUpdateChange === undefined || this._options.validateMassUpdateChange(itemProp, dataContext, formValues) !== false)) { @@ -596,7 +596,7 @@ export class SlickCompositeEditorComponent implements ExternalResource { } }); } - } + }); // update all items in the grid with the grid service if (applyToDataview) { diff --git a/packages/utils/src/domUtils.ts b/packages/utils/src/domUtils.ts index b314676ff..a9010c40b 100644 --- a/packages/utils/src/domUtils.ts +++ b/packages/utils/src/domUtils.ts @@ -69,15 +69,15 @@ export function createDomElement { if (Array.isArray(obj[key])) { destroyAllElementProps(obj[key]); } if (obj[key] instanceof HTMLElement) { obj[key] = null; } - } + }); } }