Use 'Array.prototype.forEach' instead of '_.each' and '_.forEach'

This commit is contained in:
Hongarc 2018-12-01 11:28:04 +07:00
parent d87fd095c0
commit bd8009386d
19 changed files with 74 additions and 82 deletions

View file

@ -1551,11 +1551,9 @@ GitEngine.prototype.fakeTeamwork = function(numToMake, branch) {
var deferred = Q.defer();
var chain = deferred.promise;
_.each(_.range(numToMake), function(i) {
chain = chain.then(function() {
return chainStep();
});
});
for(var i = 0; i < numToMake; i++) {
chain = chain.then(chainStep);
}
this.animationQueue.thenFinish(chain, deferred);
};
@ -2074,7 +2072,7 @@ GitEngine.prototype.hgRebase = function(destination, base) {
var masterSet = {};
masterSet[baseCommit.get('id')] = true;
_.each([upstream, downstream].concat(moreSets), function(set) {
[upstream, downstream].concat(moreSets).forEach(function(set) {
_.each(set, function(val, id) {
masterSet[id] = true;
});
@ -2085,7 +2083,7 @@ GitEngine.prototype.hgRebase = function(destination, base) {
var upstreamSet = this.getUpstreamBranchSet();
_.each(masterSet, function(val, commitID) {
// now loop over that commits branches
_.each(upstreamSet[commitID], function(branchJSON) {
upstreamSet[commitID].forEach(function(branchJSON) {
branchMap[branchJSON.id] = true;
});
});

View file

@ -85,7 +85,7 @@ var Graph = {
var commitJSON = tree.commits[objID];
var parentObjs = [];
_.each(commitJSON.parents, function(parentID) {
commitJSON.parents.forEach(function(parentID) {
parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID));
}, this);
@ -143,7 +143,7 @@ var Graph = {
var here = queue.pop();
var rents = here.get('parents');
_.each(rents, addToExplored);
(rents || []).forEach(addToExplored);
}
return exploredSet;
},
@ -151,7 +151,7 @@ var Graph = {
getUniqueObjects: function(objects) {
var unique = {};
var result = [];
_.forEach(objects, function(object) {
objects.forEach(function(object) {
if (unique[object.id]) {
return;
}

View file

@ -115,7 +115,7 @@ TreeCompare.compareAllTagsWithinTrees = function(treeA, treeB) {
TreeCompare.compareBranchesWithinTrees = function(treeA, treeB, branches) {
var result = true;
_.each(branches, function(branchName) {
branches.forEach(function(branchName) {
result = result && this.compareBranchWithinTrees(treeA, treeB, branchName);
}, this);
@ -176,7 +176,7 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran
var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB);
var result = true;
_.each(branches, function(branchName) {
branches.forEach(function(branchName) {
var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName];
@ -217,7 +217,7 @@ TreeCompare.evalAssertsOnBranch = function(tree, branchName, asserts) {
}
var result = true;
_.each(asserts, function(assert) {
asserts.forEach(function(assert) {
try {
result = result && assert(data);
} catch (err) {
@ -305,7 +305,7 @@ TreeCompare.getRecurseCompare = function(treeA, treeB, options) {
// so the index lookup is valid. for merge commits this will duplicate some of the
// checking (because we aren't doing graph search) but it's not a huge deal
var maxNumParents = Math.max(commitA.parents.length, commitB.parents.length);
_.each(_.range(maxNumParents), function(index) {
for (var index = 0; index < maxNumParents; index++) {
var pAid = commitA.parents[index];
var pBid = commitB.parents[index];
@ -315,7 +315,7 @@ TreeCompare.getRecurseCompare = function(treeA, treeB, options) {
var childB = treeB.commits[pBid];
result = result && recurseCompare(childA, childB);
}, this);
}
// if each of our children recursively are equal, we are good
return result;
};
@ -377,7 +377,7 @@ TreeCompare.reduceTreeFields = function(trees) {
tags: {}
};
_.each(trees, function(tree) {
trees.forEach(function(tree) {
_.each(treeDefaults, function(val, key) {
if (tree[key] === undefined) {
tree[key] = val;
@ -391,7 +391,7 @@ TreeCompare.reduceTreeFields = function(trees) {
_.each(objects, function(obj, objKey) {
// our blank slate to copy over
var blank = {};
_.each(saveFields, function(field) {
saveFields.forEach(function(field) {
if (obj[field] !== undefined) {
blank[field] = obj[field];
} else if (defaults[field] !== undefined) {
@ -410,7 +410,7 @@ TreeCompare.reduceTreeFields = function(trees) {
});
};
_.each(trees, function(tree) {
trees.forEach(function(tree) {
saveOnly(tree, 'commits', commitSaveFields, commitSortFields);
saveOnly(tree, 'branches', branchSaveFields);
saveOnly(tree, 'tags', tagSaveFields);

View file

@ -68,7 +68,7 @@ ParseWaterfall.prototype.addLast = function(which, value) {
};
ParseWaterfall.prototype.expandAllShortcuts = function(commandStr) {
_.each(this.shortcutWaterfall, function(shortcutMap) {
this.shortcutWaterfall.forEach(function(shortcutMap) {
commandStr = this.expandShortcut(commandStr, shortcutMap);
}, this);
return commandStr;
@ -87,13 +87,13 @@ ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) {
};
ParseWaterfall.prototype.processAllInstants = function(commandStr) {
_.each(this.instantWaterfall, function(instantCommands) {
this.instantWaterfall.forEach(function(instantCommands) {
this.processInstant(commandStr, instantCommands);
}, this);
};
ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands) {
_.each(instantCommands, function(tuple) {
instantCommands.forEach(function(tuple) {
var regex = tuple[0];
var results = regex.exec(commandStr);
if (results) {
@ -109,7 +109,7 @@ ParseWaterfall.prototype.parseAll = function(commandStr) {
}
var toReturn = false;
_.each(this.parseWaterfall, function(parseFunc) {
this.parseWaterfall.forEach(function(parseFunc) {
var results = parseFunc(commandStr);
if (results) {
toReturn = results;
@ -120,4 +120,3 @@ ParseWaterfall.prototype.parseAll = function(commandStr) {
};
exports.ParseWaterfall = ParseWaterfall;

View file

@ -93,7 +93,7 @@ var Command = Backbone.Model.extend({
deleteOptions: function(options) {
var map = this.getOptionsMap();
_.each(options, function(option) {
options.forEach(function(option) {
delete map[option];
}, this);
this.setOptionsMap(map);

View file

@ -98,7 +98,7 @@ var instantCommands = [
intl.str('show-all-commands'),
'<br/>'
];
_.each(allCommands, function(regex, command) {
allCommands.forEach(function(regex, command) {
lines.push(command);
});
@ -144,7 +144,7 @@ var getAllCommands = function() {
allCommands[vcs + ' ' + method] = regex;
});
});
_.each(toDelete, function(key) {
toDelete.forEach(function(key) {
delete allCommands[key];
});

View file

@ -41,7 +41,7 @@ var validateLevel = function(level) {
'solutionCommand'
];
_.each(requiredFields, function(field) {
requiredFields.forEach(function(field) {
if (level[field] === undefined) {
console.log(level);
throw new Error('I need this field for a level: ' + field);
@ -59,7 +59,7 @@ _.each(levelSequences, function(levels, levelSequenceName) {
}
// for this particular sequence...
_.each(levels, function(level, index) {
levels.forEach(function(level, index) {
validateLevel(level);
var id = levelSequenceName + String(index + 1);

View file

@ -173,7 +173,7 @@ var CommandPromptView = Backbone.View.extend({
which.reverse();
var str = '';
_.each(which, function(text) {
which.forEach(function(text) {
str += text + ';';
}, this);
@ -202,4 +202,3 @@ var CommandPromptView = Backbone.View.extend({
});
exports.CommandPromptView = CommandPromptView;

View file

@ -168,7 +168,7 @@ var GitDemonstrationView = ContainedBase.extend({
var chainDeferred = Q.defer();
var chainPromise = chainDeferred.promise;
_.each(commands, function(command, index) {
commands.forEach(function(command, index) {
chainPromise = chainPromise.then(function() {
var myDefer = Q.defer();
this.mainVis.gitEngine.dispatch(command, myDefer);

View file

@ -292,7 +292,7 @@ var LevelDropdownView = ContainedBase.extend({
$(selector).toggleClass('selected', value);
// also go find the series and update the about
_.each(this.seriesViews, function(view) {
this.seriesViews.forEach(function(view) {
if (view.levelIDs.indexOf(id) === -1) {
return;
}
@ -343,14 +343,14 @@ var LevelDropdownView = ContainedBase.extend({
},
updateSolvedStatus: function() {
_.each(this.seriesViews, function(view) {
this.seriesViews.forEach(function(view) {
view.updateSolvedStatus();
}, this);
},
buildSequences: function() {
this.seriesViews = [];
_.each(this.getSequencesOnTab(), function(sequenceName) {
this.getSequencesOnTab().forEach(function(sequenceName) {
this.seriesViews.push(new SeriesView({
destination: this.$el,
name: sequenceName,
@ -377,7 +377,7 @@ var SeriesView = BaseView.extend({
this.levelIDs = [];
var firstLevelInfo = null;
_.each(this.levels, function(level) {
this.levels.forEach(function(level) {
if (firstLevelInfo === null) {
firstLevelInfo = this.formatLevelAbout(level.id);
}

View file

@ -142,7 +142,7 @@ var MultiView = Backbone.View.extend({
// other views will take if they need to
this.keyboardListener.mute();
_.each(this.childViews, function(childView) {
this.childViews.forEach(function(childView) {
childView.die();
});
@ -183,7 +183,7 @@ var MultiView = Backbone.View.extend({
render: function() {
// go through each and render... show the first
_.each(this.childViewJSONs, function(childViewJSON, index) {
this.childViewJSONs.forEach(function(childViewJSON, index) {
var childView = this.createChildView(childViewJSON);
this.childViews.push(childView);
this.addNavToView(childView, index);

View file

@ -19,7 +19,7 @@ var InteractiveRebaseView = ContainedBase.extend({
this.rebaseEntries = new RebaseEntryCollection();
options.toRebase.reverse();
_.each(options.toRebase, function(commit) {
options.toRebase.forEach(function(commit) {
var id = commit.get('id');
this.rebaseMap[id] = commit;
@ -63,7 +63,7 @@ var InteractiveRebaseView = ContainedBase.extend({
// now get the real array
var toRebase = [];
_.each(uiOrder, function(id) {
uiOrder.forEach(function(id) {
// the model pick check
if (this.entryObjMap[id].get('pick')) {
toRebase.unshift(this.rebaseMap[id]);

View file

@ -58,7 +58,7 @@ GitVisuals.prototype.defer = function(action) {
};
GitVisuals.prototype.deferFlush = function() {
_.each(this.deferred, function(action) {
this.deferred.forEach(function(action) {
action();
}, this);
this.deferred = [];
@ -68,17 +68,17 @@ GitVisuals.prototype.resetAll = function() {
// make sure to copy these collections because we remove
// items in place and underscore is too dumb to detect length change
var edges = this.visEdgeCollection.toArray();
_.each(edges, function(visEdge) {
edges.forEach(function(visEdge) {
visEdge.remove();
}, this);
var branches = this.visBranchCollection.toArray();
_.each(branches, function(visBranch) {
branches.forEach(function(visBranch) {
visBranch.remove();
}, this);
var tags = this.visTagCollection.toArray();
_.each(tags, function(visTag) {
tags.forEach(function(visTag) {
visTag.remove();
}, this);
@ -332,7 +332,7 @@ GitVisuals.prototype.explodeNodes = function(speed) {
// are called unnecessarily when they have almost
// zero speed. would be interesting to see performance differences
var keepGoing = [];
_.each(funcs, function(func) {
funcs.forEach(function(func) {
if (func()) {
keepGoing.push(func);
}
@ -485,7 +485,7 @@ GitVisuals.prototype.getBlendedHuesForCommit = function(commit) {
GitVisuals.prototype.blendHuesFromBranchStack = function(branchStackArray) {
var hueStrings = [];
_.each(branchStackArray, function(branchWrapper) {
branchStackArray.forEach(function(branchWrapper) {
var fill = branchWrapper.obj.get('visBranch').get('fill');
if (fill.slice(0,3) !== 'hsb') {
@ -525,7 +525,7 @@ GitVisuals.prototype.getCommitUpstreamStatus = function(commit) {
GitVisuals.prototype.calcTagStacks = function() {
var tags = this.gitEngine.getTags();
var map = {};
_.each(tags, function(tag) {
tags.forEach(function(tag) {
var thisId = tag.target.get('id');
map[thisId] = map[thisId] || [];
@ -542,7 +542,7 @@ GitVisuals.prototype.calcTagStacks = function() {
GitVisuals.prototype.calcBranchStacks = function() {
var branches = this.gitEngine.getBranches();
var map = {};
_.each(branches, function(branch) {
branches.forEach(function(branch) {
var thisId = branch.target.get('id');
map[thisId] = map[thisId] || [];
@ -572,7 +572,7 @@ GitVisuals.prototype.calcWidth = function() {
GitVisuals.prototype.maxWidthRecursive = function(commit) {
var childrenTotalWidth = 0;
_.each(commit.get('children'), function(child) {
commit.get('children').forEach(function(child) {
// only include this if we are the "main" parent of
// this child
if (child.isMainParent(commit)) {
@ -601,14 +601,14 @@ GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) {
// basic box-flex model
var totalFlex = 0;
var children = commit.get('children');
_.each(children, function(child) {
children.forEach(function(child) {
if (child.isMainParent(commit)) {
totalFlex += child.get('visNode').getMaxWidthScaled();
}
}, this);
var prevBound = min;
_.each(children, function(child, index) {
children.forEach(function(child, index) {
if (!child.isMainParent(commit)) {
return;
}
@ -777,7 +777,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
var children = commit.get('children');
var maxDepth = depth;
_.each(children, function(child) {
children.forEach(function(child) {
var d = this.calcDepthRecursive(child, depth + 1);
maxDepth = Math.max(d, maxDepth);
}, this);
@ -924,7 +924,7 @@ function blendHueStrings(hueStrings) {
var totalBright = 0;
var length = hueStrings.length;
_.each(hueStrings, function(hueString) {
hueStrings.forEach(function(hueString) {
var exploded = hueString.split('(')[1];
exploded = exploded.split(')')[0];
exploded = exploded.split(',');

View file

@ -3,7 +3,7 @@ var Backbone = require('backbone');
var VisBase = Backbone.Model.extend({
removeKeys: function(keys) {
_.each(keys, function(key) {
keys.forEach(function(key) {
if (this.get(key)) {
this.get(key).remove();
}
@ -25,7 +25,7 @@ var VisBase = Backbone.Model.extend({
var attr = this.getAttributes();
// safely insert this attribute into all the keys we want
_.each(keys.include, function(key) {
keys.include.forEach(function(key) {
attr[key] = Object.assign(
{},
attr[key],
@ -33,7 +33,7 @@ var VisBase = Backbone.Model.extend({
);
});
_.each(keys.exclude, function(key) {
keys.exclude.forEach(function(key) {
delete attr[key];
});
@ -42,4 +42,3 @@ var VisBase = Backbone.Model.extend({
});
exports.VisBase = VisBase;

View file

@ -3,7 +3,7 @@ var Backbone = require('backbone');
var VisBase = Backbone.Model.extend({
removeKeys: function(keys) {
_.each(keys, function(key) {
keys.forEach(function(key) {
if (this.get(key)) {
this.get(key).remove();
}
@ -35,14 +35,14 @@ var VisBase = Backbone.Model.extend({
},
setAttrBase: function(keys, attr, instant, speed, easing) {
_.each(keys, function(key) {
keys.forEach(function(key) {
if (instant) {
this.get(key).attr(attr[key]);
} else {
this.get(key).stop();
this.get(key).animate(attr[key], speed, easing);
// some keys don't support animating too, so set those instantly here
_.forEach(this.getNonAnimateKeys(), function(nonAnimateKey) {
this.getNonAnimateKeys().forEach(function(nonAnimateKey) {
if (attr[key] && attr[key][nonAnimateKey] !== undefined) {
this.get(key).attr(nonAnimateKey, attr[key][nonAnimateKey]);
}
@ -70,7 +70,7 @@ var VisBase = Backbone.Model.extend({
var attr = this.getAttributes();
// safely insert this attribute into all the keys we want
_.each(keys.include, function(key) {
keys.include.forEach(function(key) {
attr[key] = Object.assign(
{},
attr[key],
@ -78,7 +78,7 @@ var VisBase = Backbone.Model.extend({
);
});
_.each(keys.exclude, function(key) {
keys.exclude.forEach(function(key) {
delete attr[key];
});
@ -87,4 +87,3 @@ var VisBase = Backbone.Model.extend({
});
exports.VisBase = VisBase;

View file

@ -167,7 +167,7 @@ var VisBranch = VisBase.extend({
var myArray = this.getBranchStackArray();
var index = -1;
_.each(myArray, function(branch, i) {
myArray.forEach(function(branch, i) {
if (branch.obj == this.get('branch')) {
index = i;
}
@ -279,7 +279,7 @@ var VisBranch = VisBase.extend({
arrowInnerLow,
arrowStartLow
];
_.each(coords, function(pos) {
coords.forEach(function(pos) {
pathStr += 'L' + toStringCoords(pos) + ' ';
}, this);
pathStr += 'z';
@ -309,7 +309,7 @@ var VisBranch = VisBase.extend({
}
var maxWidth = 0;
_.each(this.getBranchStackArray(), function(branch) {
this.getBranchStackArray().forEach(function(branch) {
maxWidth = Math.max(maxWidth, getTextWidth(
branch.obj.get('visBranch')
));
@ -432,7 +432,7 @@ var VisBranch = VisBase.extend({
// set CSS
var keys = ['text', 'rect', 'arrow'];
_.each(keys, function(key) {
keys.forEach(function(key) {
$(this.get(key).node).css(attr.css);
}, this);
@ -451,7 +451,7 @@ var VisBranch = VisBase.extend({
this.get('arrow')
];
_.each(objs, function(rObj) {
objs.forEach(function(rObj) {
rObj.click(this.onClick.bind(this));
}, this);
},
@ -577,4 +577,3 @@ var VisBranchCollection = Backbone.Collection.extend({
exports.VisBranchCollection = VisBranchCollection;
exports.VisBranch = VisBranch;
exports.randomHueString = randomHueString;

View file

@ -15,7 +15,7 @@ var VisEdge = VisBase.extend({
validateAtInit: function() {
var required = ['tail', 'head'];
_.each(required, function(key) {
required.forEach(function(key) {
if (!this.get(key)) {
throw new Error(key + ' is required!');
}

View file

@ -261,33 +261,33 @@ var VisNode = VisBase.extend({
},
setOutgoingEdgesOpacity: function(opacity) {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
edge.setOpacity(opacity);
});
},
animateOutgoingEdgesToAttr: function(snapShot, speed, easing) {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
var attr = snapShot[edge.getID()];
edge.animateToAttr(attr);
}, this);
},
animateOutgoingEdges: function(speed, easing) {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
edge.animateUpdatedPath(speed, easing);
}, this);
},
animateOutgoingEdgesFromSnapshot: function(snapshot, speed, easing) {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
var attr = snapshot[edge.getID()];
edge.animateToAttr(attr, speed, easing);
}, this);
},
setOutgoingEdgesBirthPosition: function(parentCoords) {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
var headPos = edge.get('head').getScreenCoords();
var path = edge.genSmoothBezierPathStringFromCoords(parentCoords, headPos);
edge.get('path').stop();
@ -334,7 +334,7 @@ var VisNode = VisBase.extend({
}
var commandStr = 'git checkout ' + this.get('commit').get('id');
var Main = require('../app');
_.each([this.get('circle'), this.get('text')], function(rObj) {
[this.get('circle'), this.get('text')].forEach(function(rObj) {
rObj.click(function() {
Main.getEventBaton().trigger('commandSubmitted', commandStr);
});
@ -347,7 +347,7 @@ var VisNode = VisBase.extend({
// set the opacity on my stuff
var keys = ['circle', 'text'];
_.each(keys, function(key) {
keys.forEach(function(key) {
this.get(key).attr({
opacity: opacity
});
@ -371,7 +371,7 @@ var VisNode = VisBase.extend({
},
removeAllEdges: function() {
_.each(this.get('outgoingEdges'), function(edge) {
this.get('outgoingEdges').forEach(function(edge) {
edge.remove();
}, this);
},

View file

@ -95,7 +95,7 @@ var VisTag = VisBase.extend({
var myArray = this.getTagStackArray();
var index = -1;
_.each(myArray, function(Tag, i) {
myArray.forEach(function(Tag, i) {
if (Tag.obj == this.get('tag')) {
index = i;
}
@ -175,7 +175,7 @@ var VisTag = VisBase.extend({
var textNode = this.get('text').node;
var maxWidth = 0;
_.each(this.getTagStackArray(), function(Tag) {
this.getTagStackArray().forEach(function(Tag) {
maxWidth = Math.max(maxWidth, getTextWidth(
Tag.obj.get('visTag')
));
@ -271,7 +271,7 @@ var VisTag = VisBase.extend({
// set CSS
var keys = ['text', 'rect'];
_.each(keys, function(key) {
keys.forEach(function(key) {
$(this.get(key).node).css(attr.css);
}, this);
@ -289,7 +289,7 @@ var VisTag = VisBase.extend({
this.get('text')
];
_.each(objs, function(rObj) {
objs.forEach(function(rObj) {
rObj.click(this.onClick.bind(this));
}, this);
},
@ -405,4 +405,3 @@ var VisTagCollection = Backbone.Collection.extend({
exports.VisTagCollection = VisTagCollection;
exports.VisTag = VisTag;
exports.randomHueString = randomHueString;