From 39fa4605087f1254f5ee8953211448f6bb3845b4 Mon Sep 17 00:00:00 2001 From: wnvko Date: Fri, 7 Dec 2018 10:18:18 +0200 Subject: [PATCH] refactor(igxTreeGrid): switch array.map and for loops with for-of, #2921 --- .../src/lib/data-operations/data-util.ts | 4 +-- .../services/transaction/igx-transaction.ts | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/projects/igniteui-angular/src/lib/data-operations/data-util.ts b/projects/igniteui-angular/src/lib/data-operations/data-util.ts index 57fbc432d37..05659c75cee 100644 --- a/projects/igniteui-angular/src/lib/data-operations/data-util.ts +++ b/projects/igniteui-angular/src/lib/data-operations/data-util.ts @@ -234,9 +234,7 @@ export class DataUtil { primaryKey?: any, deleteRows: boolean = false): any[] { - for (let i = 0; i < transactions.length; i++) { - const transaction = transactions[i]; - + for (const transaction of transactions) { if (transaction.path) { const parent = this.findParentFromPath(data, primaryKey, childDataKey, transaction.path); let collection: any[] = parent ? parent[childDataKey] : data; diff --git a/projects/igniteui-angular/src/lib/services/transaction/igx-transaction.ts b/projects/igniteui-angular/src/lib/services/transaction/igx-transaction.ts index 6a8e3caeb95..c8f6e433956 100644 --- a/projects/igniteui-angular/src/lib/services/transaction/igx-transaction.ts +++ b/projects/igniteui-angular/src/lib/services/transaction/igx-transaction.ts @@ -86,8 +86,7 @@ export class IgxTransactionService exten this._isPending = false; if (commit) { const actions: { transaction: T, recordRef: any }[] = []; - for (let i = 0; i < this._pendingTransactions.length; i++) { - const transaction: T = this._pendingTransactions[i]; + for (const transaction of this._pendingTransactions) { const pendingState = this._pendingStates.get(transaction.id); this._transactions.push(transaction); this.updateState(this._states, transaction, pendingState.recordRef); @@ -135,12 +134,17 @@ export class IgxTransactionService exten return; } - const actions: { transaction: T, recordRef: any }[] = this._undoStack.pop(); - this._transactions.splice(this._transactions.length - actions.length); - this._redoStack.push(actions); + const lastActions: { transaction: T, recordRef: any }[] = this._undoStack.pop(); + this._transactions.splice(this._transactions.length - lastActions.length); + this._redoStack.push(lastActions); this._states.clear(); - this._undoStack.map(a => a.map(t => this.updateState(this._states, t.transaction, t.recordRef))); + for (const currentActions of this._undoStack) { + for (const transaction of currentActions) { + this.updateState(this._states, transaction.transaction, transaction.recordRef); + } + } + this.onStateUpdate.emit(); } @@ -148,10 +152,11 @@ export class IgxTransactionService exten if (this._redoStack.length > 0) { let actions: { transaction: T, recordRef: any, useInUndo?: boolean }[]; actions = this._redoStack.pop(); - actions.map(a => { - this.updateState(this._states, a.transaction, a.recordRef); - this._transactions.push(a.transaction); - }); + for (const action of actions) { + this.updateState(this._states, action.transaction, action.recordRef); + this._transactions.push(action.transaction); + } + this._undoStack.push(actions); this.onStateUpdate.emit(); }