Replace some '_.each' with 'Array.prototype.forEach'

This commit is contained in:
Hongarc 2018-12-01 08:05:27 +07:00
parent 489a4b9095
commit 0134bf9870
4 changed files with 50 additions and 56 deletions

View file

@ -62,7 +62,7 @@ module.exports = function(grunt) {
hashedMinFile = 'bundle.js'; hashedMinFile = 'bundle.js';
} }
var jsRegex = /bundle\.min\.\w+\.js/; var jsRegex = /bundle\.min\.\w+\.js/;
_.each(buildFiles, function(jsFile) { buildFiles.forEach(function(jsFile) {
if (jsRegex.test(jsFile)) { if (jsRegex.test(jsFile)) {
if (hashedMinFile) { if (hashedMinFile) {
throw new Error('more than one hashed file: ' + jsFile + hashedMinFile); throw new Error('more than one hashed file: ' + jsFile + hashedMinFile);
@ -76,7 +76,7 @@ module.exports = function(grunt) {
var styleRegex = /main\.\w+\.css/; var styleRegex = /main\.\w+\.css/;
var hashedStyleFile; var hashedStyleFile;
_.each(buildFiles, function(styleFile) { buildFiles.forEach(function(styleFile) {
if (styleRegex.test(styleFile)) { if (styleRegex.test(styleFile)) {
if (hashedStyleFile) { if (hashedStyleFile) {
throw new Error('more than one hashed style: ' + styleFile + hashedStyleFile); throw new Error('more than one hashed style: ' + styleFile + hashedStyleFile);
@ -253,4 +253,3 @@ module.exports = function(grunt) {
grunt.registerTask('test', ['jasmine_node']); grunt.registerTask('test', ['jasmine_node']);
grunt.registerTask('casperTest', ['shell:casperTest']); grunt.registerTask('casperTest', ['shell:casperTest']);
}; };

View file

@ -34,7 +34,7 @@ var commands = {
if (result.multiDelegate) { if (result.multiDelegate) {
// we need to do multiple delegations with // we need to do multiple delegations with
// a different command at each step // a different command at each step
_.each(result.multiDelegate, function(delConfig) { result.multiDelegate.forEach(function(delConfig) {
// copy command, and then set opts // copy command, and then set opts
commandObj.setOptionsMap(delConfig.options || {}); commandObj.setOptionsMap(delConfig.options || {});
commandObj.setGeneralArgs(delConfig.args || []); commandObj.setGeneralArgs(delConfig.args || []);
@ -70,7 +70,7 @@ var commands = {
var displayName = config.displayName || name; var displayName = config.displayName || name;
var thisMap = {}; var thisMap = {};
// start all options off as disabled // start all options off as disabled
_.each(config.options, function(option) { (config.options || []).forEach(function(option) {
thisMap[option] = false; thisMap[option] = false;
}); });
optionMap[vcs][displayName] = thisMap; optionMap[vcs][displayName] = thisMap;

View file

@ -431,7 +431,7 @@ var commandConfig = {
names = names.concat(generalArgs); names = names.concat(generalArgs);
command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d'); command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d');
_.each(names, function(name) { names.forEach(function(name) {
engine.validateAndDeleteBranch(name); engine.validateAndDeleteBranch(name);
}); });
return; return;
@ -856,4 +856,3 @@ var instantCommands = [
exports.commandConfig = commandConfig; exports.commandConfig = commandConfig;
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;

View file

@ -170,7 +170,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) {
// now loop through and delete commits // now loop through and delete commits
var commitsToLoop = tree.commits; var commitsToLoop = tree.commits;
tree.commits = {}; tree.commits = {};
_.each(commitsToLoop, function(commit, id) { commitsToLoop.forEach(function(commit, id) {
if (set[id]) { if (set[id]) {
// if included in target branch // if included in target branch
tree.commits[id] = commit; tree.commits[id] = commit;
@ -179,7 +179,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) {
var branchesToLoop = tree.branches; var branchesToLoop = tree.branches;
tree.branches = {}; tree.branches = {};
_.each(branchesToLoop, function(branch, id) { branchesToLoop.forEach(function(branch, id) {
if (id === branchName) { if (id === branchName) {
tree.branches[id] = branch; tree.branches[id] = branch;
} }
@ -200,30 +200,28 @@ GitEngine.prototype.exportTree = function() {
HEAD: null HEAD: null
}; };
_.each(this.branchCollection.toJSON(), function(branch) { this.branchCollection.toJSON().forEach(function(branch) {
branch.target = branch.target.get('id'); branch.target = branch.target.get('id');
delete branch.visBranch; delete branch.visBranch;
totalExport.branches[branch.id] = branch; totalExport.branches[branch.id] = branch;
}); });
_.each(this.commitCollection.toJSON(), function(commit) { this.commitCollection.toJSON().forEach(function(commit) {
// clear out the fields that reference objects and create circular structure // clear out the fields that reference objects and create circular structure
_.each(Commit.prototype.constants.circularFields, function(field) { Commit.prototype.constants.circularFields.forEach(function(field) {
delete commit[field]; delete commit[field];
}, this); });
// convert parents // convert parents
var parents = []; commit.parents = (commit.parents || []).map(function(par) {
_.each(commit.parents, function(par) { return par.get('id');
parents.push(par.get('id'));
}); });
commit.parents = parents;
totalExport.commits[commit.id] = commit; totalExport.commits[commit.id] = commit;
}, this); }, this);
_.each(this.tagCollection.toJSON(), function(tag) { this.tagCollection.toJSON().forEach(function(tag) {
delete tag.visTag; delete tag.visTag;
tag.target = tag.target.get('id'); tag.target = tag.target.get('id');
@ -558,9 +556,8 @@ GitEngine.prototype.getOrMakeRecursive = function(
// for commits, we need to grab all the parents // for commits, we need to grab all the parents
var commitJSON = tree.commits[objID]; var commitJSON = tree.commits[objID];
var parentObjs = []; var parentObjs = commitJSON.parents.map(function(parentID) {
_.each(commitJSON.parents, function(parentID) { return this.getOrMakeRecursive(tree, createdSoFar, parentID);
parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID));
}, this); }, this);
var commit = new Commit(Object.assign( var commit = new Commit(Object.assign(
@ -774,17 +771,16 @@ GitEngine.prototype.printBranchesWithout = function(without) {
var commitToBranches = this.getUpstreamBranchSet(); var commitToBranches = this.getUpstreamBranchSet();
var commitID = this.getCommitFromRef(without).get('id'); var commitID = this.getCommitFromRef(without).get('id');
var toPrint = []; var toPrint = commitToBranches[commitID].map(function (branchJSON) {
_.each(commitToBranches[commitID], function(branchJSON) {
branchJSON.selected = this.HEAD.get('target').get('id') == branchJSON.id; branchJSON.selected = this.HEAD.get('target').get('id') == branchJSON.id;
toPrint.push(branchJSON); return branchJSON;
}, this); }, this);
this.printBranches(toPrint); this.printBranches(toPrint);
}; };
GitEngine.prototype.printBranches = function(branches) { GitEngine.prototype.printBranches = function(branches) {
var result = ''; var result = '';
_.each(branches, function(branch) { branches.forEach(function (branch) {
result += (branch.selected ? '* ' : '') + branch.id + '\n'; result += (branch.selected ? '* ' : '') + branch.id + '\n';
}); });
throw new CommandResult({ throw new CommandResult({
@ -794,7 +790,7 @@ GitEngine.prototype.printBranches = function(branches) {
GitEngine.prototype.printTags = function(tags) { GitEngine.prototype.printTags = function(tags) {
var result = ''; var result = '';
_.each(tags, function(tag) { tags.forEach(function (tag) {
result += tag.id + '\n'; result += tag.id + '\n';
}); });
throw new CommandResult({ throw new CommandResult({
@ -895,11 +891,11 @@ GitEngine.prototype.revert = function(whichCommits) {
}.bind(this); }.bind(this);
// set up the promise chain // set up the promise chain
_.each(toRevert, function(commit) { toRevert.forEach(function (commit) {
chain = chain.then(function() { chain = chain.then(function() {
return chainStep(commit); return chainStep(commit);
}); });
}, this); });
// done! update our location // done! update our location
chain = chain.then(function() { chain = chain.then(function() {
@ -934,7 +930,7 @@ GitEngine.prototype.setupCherrypickChain = function(toCherrypick) {
); );
}.bind(this); }.bind(this);
_.each(toCherrypick, function(arg) { toCherrypick.forEach(function (arg) {
chain = chain.then(function() { chain = chain.then(function() {
return chainStep(arg); return chainStep(arg);
}); });
@ -1015,7 +1011,7 @@ GitEngine.prototype.getTargetGraphDifference = function(
while (toExplore.length) { while (toExplore.length) {
var here = toExplore.pop(); var here = toExplore.pop();
difference.push(here); difference.push(here);
_.each(here.parents, pushParent); here.parents.forEach(pushParent);
} }
// filter because we weren't doing graph search // filter because we weren't doing graph search
@ -1160,7 +1156,7 @@ GitEngine.prototype.push = function(options) {
var deferred = Q.defer(); var deferred = Q.defer();
var chain = deferred.promise; var chain = deferred.promise;
_.each(commitsToMake, function(commitJSON) { commitsToMake.forEach(function(commitJSON) {
chain = chain.then(function() { chain = chain.then(function() {
return this.animationFactory.playHighlightPromiseAnimation( return this.animationFactory.playHighlightPromiseAnimation(
this.refs[commitJSON.id], this.refs[commitJSON.id],
@ -1267,7 +1263,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
// first check if our local remote branch is upstream of the origin branch set. // first check if our local remote branch is upstream of the origin branch set.
// this check essentially pretends the local remote branch is in origin and // this check essentially pretends the local remote branch is in origin and
// could be fast forwarded (basic sanity check) // could be fast forwarded (basic sanity check)
_.each(sourceDestPairs, function(pair) { sourceDestPairs.forEach(function (pair) {
this.checkUpstreamOfSource( this.checkUpstreamOfSource(
this, this,
this.origin, this.origin,
@ -1278,7 +1274,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
// then we get the difference in commits between these two graphs // then we get the difference in commits between these two graphs
var commitsToMake = []; var commitsToMake = [];
_.each(sourceDestPairs, function(pair) { sourceDestPairs.forEach(function (pair) {
commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( commitsToMake = commitsToMake.concat(this.getTargetGraphDifference(
this, this,
this.origin, this.origin,
@ -1341,7 +1337,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
} }
var originBranchSet = this.origin.getUpstreamBranchSet(); var originBranchSet = this.origin.getUpstreamBranchSet();
_.each(commitsToMake, function(commitJSON) { commitsToMake.forEach(function (commitJSON) {
// technically we could grab the wrong one here // technically we could grab the wrong one here
// but this works for now // but this works for now
var originBranch = originBranchSet[commitJSON.id][0].obj; var originBranch = originBranchSet[commitJSON.id][0].obj;
@ -1364,7 +1360,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
chain = chain.then(function() { chain = chain.then(function() {
// update all the destinations // update all the destinations
_.each(sourceDestPairs, function(pair) { sourceDestPairs.forEach(function (pair) {
var ours = this.refs[pair.destination]; var ours = this.refs[pair.destination];
var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id'); var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id');
// by definition we just made the commit with this id, // by definition we just made the commit with this id,
@ -1736,8 +1732,8 @@ GitEngine.prototype.updateBranchesFromSet = function(commitSet) {
var branchesToUpdate = {}; var branchesToUpdate = {};
// now loop over the set we got passed in and find which branches // now loop over the set we got passed in and find which branches
// that means (aka intersection) // that means (aka intersection)
_.each(commitSet, function(val, id) { commitSet.forEach(function (val, id) {
_.each(upstreamSet[id], function(branchJSON) { upstreamSet[id].forEach(function (branchJSON) {
branchesToUpdate[branchJSON.id] = true; branchesToUpdate[branchJSON.id] = true;
}); });
}, this); }, this);
@ -1777,7 +1773,7 @@ GitEngine.prototype.syncRemoteBranchFills = function() {
GitEngine.prototype.updateBranchesForHg = function(branchList) { GitEngine.prototype.updateBranchesForHg = function(branchList) {
var hasUpdated = false; var hasUpdated = false;
_.each(branchList, function(branchID) { branchList.forEach(function (branchID) {
// ok now just check if this branch has a more recent commit available. // ok now just check if this branch has a more recent commit available.
// that mapping is easy because we always do rebase alt id -- // that mapping is easy because we always do rebase alt id --
// theres no way to have C3' and C3''' but no C3''. so just // theres no way to have C3' and C3''' but no C3''. so just
@ -1846,7 +1842,7 @@ GitEngine.prototype.pruneTree = function() {
this.command.addWarning(intl.str('hg-prune-tree')); this.command.addWarning(intl.str('hg-prune-tree'));
} }
_.each(toDelete, function(commit) { toDelete.forEach(function (commit) {
commit.removeFromParents(); commit.removeFromParents();
this.commitCollection.remove(commit); this.commitCollection.remove(commit);
@ -1877,7 +1873,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) {
var inArray = function(arr, id) { var inArray = function(arr, id) {
var found = false; var found = false;
_.each(arr, function(wrapper) { arr.forEach(function (wrapper) {
if (wrapper.id == id) { if (wrapper.id == id) {
found = true; found = true;
} }
@ -1902,7 +1898,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) {
collection.each(function(ref) { collection.each(function(ref) {
var set = bfsSearch(ref.get('target')); var set = bfsSearch(ref.get('target'));
_.each(set, function(id) { set.forEach(function (id) {
commitToSet[id] = commitToSet[id] || []; commitToSet[id] = commitToSet[id] || [];
// only add it if it's not there, so hue blending is ok // only add it if it's not there, so hue blending is ok
@ -2156,7 +2152,7 @@ GitEngine.prototype.rebase = function(targetSource, currentLocation, options) {
GitEngine.prototype.getUpstreamDiffSetFromSet = function(stopSet, location) { GitEngine.prototype.getUpstreamDiffSetFromSet = function(stopSet, location) {
var set = {}; var set = {};
_.each(this.getUpstreamDiffFromSet(stopSet, location), function(commit) { this.getUpstreamDiffFromSet(stopSet, location).forEach(function (commit) {
set[commit.get('id')] = true; set[commit.get('id')] = true;
}); });
return set; return set;
@ -2189,7 +2185,7 @@ GitEngine.prototype.getInteractiveRebaseCommits = function(targetSource, current
// throw out merge's real fast and see if we have anything to do // throw out merge's real fast and see if we have anything to do
var toRebase = []; var toRebase = [];
_.each(toRebaseRough, function(commit) { toRebaseRough.forEach(function (commit) {
if (commit.get('parents').length == 1) { if (commit.get('parents').length == 1) {
toRebase.push(commit); toRebase.push(commit);
} }
@ -2211,7 +2207,7 @@ GitEngine.prototype.rebaseInteractiveTest = function(targetSource, currentLocati
var toRebase = this.getInteractiveRebaseCommits(targetSource, currentLocation); var toRebase = this.getInteractiveRebaseCommits(targetSource, currentLocation);
var rebaseMap = {}; var rebaseMap = {};
_.each(toRebase, function(commit) { toRebase.forEach(function (commit) {
var id = commit.get('id'); var id = commit.get('id');
rebaseMap[id] = commit; rebaseMap[id] = commit;
}); });
@ -2228,7 +2224,7 @@ GitEngine.prototype.rebaseInteractiveTest = function(targetSource, currentLocati
// Verify each chosen commit exists in the list of commits given to the user // Verify each chosen commit exists in the list of commits given to the user
var extraCommits = []; var extraCommits = [];
rebaseOrder = []; rebaseOrder = [];
_.each(idsToRebase, function(id) { idsToRebase.forEach(function (id) {
if (id in rebaseMap) { if (id in rebaseMap) {
rebaseOrder.push(rebaseMap[id]); rebaseOrder.push(rebaseMap[id]);
} else { } else {
@ -2281,13 +2277,13 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation,
var initialCommitOrdering; var initialCommitOrdering;
if (options.initialCommitOrdering && options.initialCommitOrdering.length > 0) { if (options.initialCommitOrdering && options.initialCommitOrdering.length > 0) {
var rebaseMap = {}; var rebaseMap = {};
_.each(toRebase, function(commit) { toRebase.forEach(function (commit) {
rebaseMap[commit.get('id')] = true; rebaseMap[commit.get('id')] = true;
}); });
// Verify each chosen commit exists in the list of commits given to the user // Verify each chosen commit exists in the list of commits given to the user
initialCommitOrdering = []; initialCommitOrdering = [];
_.each(options.initialCommitOrdering[0].split(','), function(id) { options.initialCommitOrdering[0].split(',').forEach(function (id) {
if (!rebaseMap[id]) { if (!rebaseMap[id]) {
throw new GitError({ throw new GitError({
msg: intl.todo('Hey those commits don\'t exist in the set!') msg: intl.todo('Hey those commits don\'t exist in the set!')
@ -2406,7 +2402,7 @@ GitEngine.prototype.rebaseFinish = function(
}.bind(this); }.bind(this);
// set up the promise chain // set up the promise chain
_.each(toRebase, function(commit) { toRebase.forEach(function (commit) {
chain = chain.then(function() { chain = chain.then(function() {
return chainStep(commit); return chainStep(commit);
}); });
@ -2561,7 +2557,7 @@ GitEngine.prototype.describe = function(ref) {
// ok we need to BFS from start upwards until we hit a tag. but // ok we need to BFS from start upwards until we hit a tag. but
// first we need to get a reverse mapping from tag to commit // first we need to get a reverse mapping from tag to commit
var tagMap = {}; var tagMap = {};
_.each(this.tagCollection.toJSON(), function(tag) { this.tagCollection.toJSON().forEach(function (tag) {
tagMap[tag.target.get('id')] = tag.id; tagMap[tag.target.get('id')] = tag.id;
}); });
@ -2733,7 +2729,7 @@ GitEngine.prototype.status = function() {
lines.push(intl.str('git-status-readytocommit')); lines.push(intl.str('git-status-readytocommit'));
var msg = ''; var msg = '';
_.each(lines, function(line) { lines.forEach(function (line) {
msg += '# ' + line + '\n'; msg += '# ' + line + '\n';
}); });
@ -2776,7 +2772,7 @@ GitEngine.prototype.log = function(ref, omitSet) {
// now go through and collect logs // now go through and collect logs
var bigLogStr = ''; var bigLogStr = '';
_.each(toDump, function(c) { toDump.forEach(function (c) {
bigLogStr += c.getLogEntry(); bigLogStr += c.getLogEntry();
}, this); }, this);
@ -2831,7 +2827,7 @@ GitEngine.prototype.getDownstreamSet = function(ancestor) {
var here = queue.pop(); var here = queue.pop();
var children = here.get('children'); var children = here.get('children');
_.each(children, addToExplored); children.forEach(addToExplored);
} }
return exploredSet; return exploredSet;
}; };
@ -3009,7 +3005,7 @@ var Commit = Backbone.Model.extend({
}, },
removeFromParents: function() { removeFromParents: function() {
_.each(this.get('parents'), function(parent) { this.get('parents').forEach(function (parent) {
parent.removeChild(this); parent.removeChild(this);
}, this); }, this);
}, },
@ -3052,11 +3048,11 @@ var Commit = Backbone.Model.extend({
removeChild: function(childToRemove) { removeChild: function(childToRemove) {
var newChildren = []; var newChildren = [];
_.each(this.get('children'), function(child) { this.get('children').forEach(function (child) {
if (child !== childToRemove) { if (child !== childToRemove) {
newChildren.push(child); newChildren.push(child);
} }
}, this); });
this.set('children', newChildren); this.set('children', newChildren);
}, },
@ -3069,7 +3065,7 @@ var Commit = Backbone.Model.extend({
this.validateAtInit(); this.validateAtInit();
this.addNodeToVisuals(); this.addNodeToVisuals();
_.each(this.get('parents'), function(parent) { (this.get('parents') || []).forEach(function (parent) {
parent.get('children').push(this); parent.get('children').push(this);
this.addEdgeToVisuals(parent); this.addEdgeToVisuals(parent);
}, this); }, this);