Skip to content

Commit

Permalink
refactor(igxTreeGrid): switch array.map and for loops with for-of, #2921
Browse files Browse the repository at this point in the history
  • Loading branch information
wnvko committed Dec 7, 2018
1 parent 98d2a57 commit 39fa460
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class IgxTransactionService<T extends Transaction, S extends State> 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);
Expand Down Expand Up @@ -135,23 +134,29 @@ export class IgxTransactionService<T extends Transaction, S extends State> 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();
}

public redo(): void {
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();
}
Expand Down

0 comments on commit 39fa460

Please sign in to comment.