Commit 00b75ff4 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'allenlai18/gitlab-allenlai/I-36458' into 'master'

Use ES6 methods instead of `for` loops

See merge request gitlab-org/gitlab!37324
parents 28c41bd6 94129c4d
...@@ -40,9 +40,6 @@ export default class BranchGraph { ...@@ -40,9 +40,6 @@ export default class BranchGraph {
} }
prepareData(days, commits) { prepareData(days, commits) {
let c = 0;
let j = 0;
let len = 0;
this.days = days; this.days = days;
this.commits = commits; this.commits = commits;
this.collectParents(); this.collectParents();
...@@ -53,38 +50,33 @@ export default class BranchGraph { ...@@ -53,38 +50,33 @@ export default class BranchGraph {
this.r = Raphael(this.element.get(0), cw, ch); this.r = Raphael(this.element.get(0), cw, ch);
this.top = this.r.set(); this.top = this.r.set();
this.barHeight = Math.max(this.graphHeight, this.unitTime * this.days.length + 320); this.barHeight = Math.max(this.graphHeight, this.unitTime * this.days.length + 320);
const ref = this.commits; this.commits = this.commits.reduce((acc, commit) => {
for (j = 0, len = ref.length; j < len; j += 1) { const updatedCommit = commit;
c = ref[j]; if (commit.id in this.parents) {
if (c.id in this.parents) { updatedCommit.isParent = true;
c.isParent = true;
} }
this.preparedCommits[c.id] = c; acc.push(updatedCommit);
this.markCommit(c); this.preparedCommits[commit.id] = commit;
} this.markCommit(commit);
return acc;
}, []);
return this.collectColors(); return this.collectColors();
} }
collectParents() { collectParents() {
let j = 0;
let l = 0;
let len = 0;
let len1 = 0;
const ref = this.commits; const ref = this.commits;
const results = []; const results = [];
for (j = 0, len = ref.length; j < len; j += 1) { ref.forEach(c => {
const c = ref[j];
this.mtime = Math.max(this.mtime, c.time); this.mtime = Math.max(this.mtime, c.time);
this.mspace = Math.max(this.mspace, c.space); this.mspace = Math.max(this.mspace, c.space);
const ref1 = c.parents; const ref1 = c.parents;
const results1 = []; const results1 = [];
for (l = 0, len1 = ref1.length; l < len1; l += 1) { ref1.forEach(p => {
const p = ref1[l];
this.parents[p[0]] = true; this.parents[p[0]] = true;
results1.push((this.mspace = Math.max(this.mspace, p[1]))); results1.push((this.mspace = Math.max(this.mspace, p[1])));
} });
results.push(results1); results.push(results1);
} });
return results; return results;
} }
...@@ -114,7 +106,6 @@ export default class BranchGraph { ...@@ -114,7 +106,6 @@ export default class BranchGraph {
fill: '#444', fill: '#444',
}); });
const ref = this.days; const ref = this.days;
for (mm = 0, len = ref.length; mm < len; mm += 1) { for (mm = 0, len = ref.length; mm < len; mm += 1) {
const day = ref[mm]; const day = ref[mm];
if (cuday !== day[0] || cumonth !== day[1]) { if (cuday !== day[0] || cumonth !== day[1]) {
...@@ -295,7 +286,6 @@ export default class BranchGraph { ...@@ -295,7 +286,6 @@ export default class BranchGraph {
const { r } = this; const { r } = this;
const ref = commit.parents; const ref = commit.parents;
const results = []; const results = [];
for (i = 0, len = ref.length; i < len; i += 1) { for (i = 0, len = ref.length; i < len; i += 1) {
const parent = ref[i]; const parent = ref[i];
const parentCommit = this.preparedCommits[parent[0]]; const parentCommit = this.preparedCommits[parent[0]];
......
---
title: Use ES6 methods instead of `for` loops
merge_request: 37324
author: allenlai18
type: other
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment