Merge pull request #509 from Hongarc/simple

Use simple method of Nodejs instead of `underscore`
This commit is contained in:
Peter Cottle 2018-12-01 10:22:07 -08:00 committed by GitHub
commit 30458e8dbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 243 additions and 261 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

@ -1,4 +1,3 @@
var _ = require('underscore');
var intl = require('../intl'); var intl = require('../intl');
var Errors = require('../util/errors'); var Errors = require('../util/errors');
@ -34,7 +33,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 +69,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;
@ -102,8 +101,10 @@ var commands = {
}, },
loop: function(callback, context) { loop: function(callback, context) {
_.each(commandConfigs, function(commandConfig, vcs) { Object.keys(commandConfigs).forEach(function(vcs) {
_.each(commandConfig, function(config, name) { var commandConfig = commandConfigs[vcs];
Object.keys(commandConfig).forEach(function(name) {
var config = commandConfig[name];
callback(config, name, vcs); callback(config, name, vcs);
}); });
}); });
@ -116,8 +117,11 @@ var parse = function(str) {
var options; var options;
// see if we support this particular command // see if we support this particular command
_.each(commands.getRegexMap(), function (map, thisVCS) { var regexMap = commands.getRegexMap();
_.each(map, function(regex, thisMethod) { Object.keys(regexMap).forEach(function (thisVCS) {
var map = regexMap[thisVCS];
Object.keys(map).forEach(function(thisMethod) {
var regex = map[thisMethod];
if (regex.exec(str)) { if (regex.exec(str)) {
vcs = thisVCS; vcs = thisVCS;
method = thisMethod; method = thisMethod;

View file

@ -1,4 +1,4 @@
var _ = require('underscore'); var escapeString = require('../util/escapeString');
var intl = require('../intl'); var intl = require('../intl');
var Graph = require('../graph'); var Graph = require('../graph');
@ -190,7 +190,7 @@ var commandConfig = {
var set = Graph.getUpstreamSet(engine, 'HEAD'); var set = Graph.getUpstreamSet(engine, 'HEAD');
// first resolve all the refs (as an error check) // first resolve all the refs (as an error check)
var toCherrypick = _.map(generalArgs, function(arg) { var toCherrypick = generalArgs.map(function (arg) {
var commit = engine.getCommitFromRef(arg); var commit = engine.getCommitFromRef(arg);
// and check that its not upstream // and check that its not upstream
if (set[commit.get('id')]) { if (set[commit.get('id')]) {
@ -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;
@ -830,7 +830,7 @@ var instantCommands = [
intl.str('git-version'), intl.str('git-version'),
'<br/>', '<br/>',
intl.str('git-usage'), intl.str('git-usage'),
_.escape(intl.str('git-usage-command')), escapeString(intl.str('git-usage-command')),
'<br/>', '<br/>',
intl.str('git-supported-commands'), intl.str('git-supported-commands'),
'<br/>' '<br/>'
@ -838,9 +838,10 @@ var instantCommands = [
var commands = require('../commands').commands.getOptionMap()['git']; var commands = require('../commands').commands.getOptionMap()['git'];
// build up a nice display of what we support // build up a nice display of what we support
_.each(commands, function(commandOptions, command) { Object.keys(commands).forEach(function(command) {
var commandOptions = commands[command];
lines.push('git ' + command); lines.push('git ' + command);
_.each(commandOptions, function(vals, optionName) { Object.keys(commandOptions).forEach(function(optionName) {
lines.push('\t ' + optionName); lines.push('\t ' + optionName);
}, this); }, this);
}, this); }, this);
@ -856,4 +857,3 @@ var instantCommands = [
exports.commandConfig = commandConfig; exports.commandConfig = commandConfig;
exports.instantCommands = instantCommands; exports.instantCommands = instantCommands;

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Q = require('q'); var Q = require('q');
@ -170,7 +169,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 +178,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 +199,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');
@ -282,18 +279,18 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
// now we do the loading part // now we do the loading part
var createdSoFar = {}; var createdSoFar = {};
_.each(tree.commits, function(commitJSON) { Object.values(tree.commits).forEach(function(commitJSON) {
var commit = this.getOrMakeRecursive(tree, createdSoFar, commitJSON.id, this.gitVisuals); var commit = this.getOrMakeRecursive(tree, createdSoFar, commitJSON.id, this.gitVisuals);
this.commitCollection.add(commit); this.commitCollection.add(commit);
}, this); }, this);
_.each(tree.branches, function(branchJSON) { Object.values(tree.branches).forEach(function(branchJSON) {
var branch = this.getOrMakeRecursive(tree, createdSoFar, branchJSON.id, this.gitVisuals); var branch = this.getOrMakeRecursive(tree, createdSoFar, branchJSON.id, this.gitVisuals);
this.branchCollection.add(branch, {silent: true}); this.branchCollection.add(branch, {silent: true});
}, this); }, this);
_.each(tree.tags, function(tagJSON) { Object.values(tree.tags || {}).forEach(function(tagJSON) {
var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id, this.gitVisuals); var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id, this.gitVisuals);
this.tagCollection.add(tag, {silent: true}); this.tagCollection.add(tag, {silent: true});
@ -362,7 +359,8 @@ GitEngine.prototype.makeOrigin = function(treeString) {
var originTree = JSON.parse(unescape(treeString)); var originTree = JSON.parse(unescape(treeString));
// make an origin branch for each branch mentioned in the tree if its // make an origin branch for each branch mentioned in the tree if its
// not made already... // not made already...
_.each(originTree.branches, function(branchJSON, branchName) { Object.keys(originTree.branches).forEach(function(branchName) {
var branchJSON = originTree.branches[branchName];
if (this.refs[ORIGIN_PREFIX + branchName]) { if (this.refs[ORIGIN_PREFIX + branchName]) {
// we already have this branch // we already have this branch
return; return;
@ -518,7 +516,7 @@ GitEngine.prototype.getOrMakeRecursive = function(
if (type == 'HEAD') { if (type == 'HEAD') {
var headJSON = tree.HEAD; var headJSON = tree.HEAD;
var HEAD = new Ref(_.extend( var HEAD = new Ref(Object.assign(
tree.HEAD, tree.HEAD,
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target)
@ -531,7 +529,7 @@ GitEngine.prototype.getOrMakeRecursive = function(
if (type == 'branch') { if (type == 'branch') {
var branchJSON = tree.branches[objID]; var branchJSON = tree.branches[objID];
var branch = new Branch(_.extend( var branch = new Branch(Object.assign(
tree.branches[objID], tree.branches[objID],
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target)
@ -544,7 +542,7 @@ GitEngine.prototype.getOrMakeRecursive = function(
if (type == 'tag') { if (type == 'tag') {
var tagJSON = tree.tags[objID]; var tagJSON = tree.tags[objID];
var tag = new Tag(_.extend( var tag = new Tag(Object.assign(
tree.tags[objID], tree.tags[objID],
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target)
@ -558,12 +556,11 @@ 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(_.extend( var commit = new Commit(Object.assign(
commitJSON, commitJSON,
{ {
parents: parentObjs, parents: parentObjs,
@ -726,7 +723,7 @@ GitEngine.prototype.makeTag = function(id, target) {
}; };
GitEngine.prototype.getHead = function() { GitEngine.prototype.getHead = function() {
return _.clone(this.HEAD); return Object.assign({}, this.HEAD);
}; };
GitEngine.prototype.getTags = function() { GitEngine.prototype.getTags = function() {
@ -758,14 +755,14 @@ GitEngine.prototype.getBranches = function() {
GitEngine.prototype.getRemoteBranches = function() { GitEngine.prototype.getRemoteBranches = function() {
var all = this.getBranches(); var all = this.getBranches();
return _.filter(all, function(branchJSON) { return all.filter(function(branchJSON) {
return branchJSON.remote === true; return branchJSON.remote === true;
}); });
}; };
GitEngine.prototype.getLocalBranches = function() { GitEngine.prototype.getLocalBranches = function() {
var all = this.getBranches(); var all = this.getBranches();
return _.filter(all, function(branchJSON) { return all.filter(function(branchJSON) {
return branchJSON.remote === false; return branchJSON.remote === false;
}); });
}; };
@ -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({
@ -846,7 +842,7 @@ GitEngine.prototype.makeCommit = function(parents, id, options) {
id = this.getUniqueID(); id = this.getUniqueID();
} }
var commit = new Commit(_.extend({ var commit = new Commit(Object.assign({
parents: parents, parents: parents,
id: id, id: id,
gitVisuals: this.gitVisuals gitVisuals: this.gitVisuals
@ -861,7 +857,7 @@ GitEngine.prototype.makeCommit = function(parents, id, options) {
GitEngine.prototype.revert = function(whichCommits) { GitEngine.prototype.revert = function(whichCommits) {
// resolve the commits we will rebase // resolve the commits we will rebase
var toRevert = _.map(whichCommits, function(stringRef) { var toRevert = whichCommits.map(function(stringRef) {
return this.getCommitFromRef(stringRef); return this.getCommitFromRef(stringRef);
}, this); }, this);
@ -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
@ -1135,14 +1131,14 @@ GitEngine.prototype.push = function(options) {
// and remote master might be commits C2, C3, and C4, but the remote // and remote master might be commits C2, C3, and C4, but the remote
// might already have those commits. In this case, we don't need to // might already have those commits. In this case, we don't need to
// make them, so filter these out // make them, so filter these out
commitsToMake = _.filter(commitsToMake, function(commitJSON) { commitsToMake = commitsToMake.filter(function(commitJSON) {
return !this.origin.refs[commitJSON.id]; return !this.origin.refs[commitJSON.id];
}, this); }, this);
var makeCommit = function(id, parentIDs) { var makeCommit = function(id, parentIDs) {
// need to get the parents first. since we order by depth, we know // need to get the parents first. since we order by depth, we know
// the dependencies are there already // the dependencies are there already
var parents = _.map(parentIDs, function(parentID) { var parents = parentIDs.map(function(parentID) {
return this.origin.refs[parentID]; return this.origin.refs[parentID];
}, this); }, this);
return this.origin.makeCommit(parents, id); return this.origin.makeCommit(parents, id);
@ -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],
@ -1250,7 +1246,7 @@ GitEngine.prototype.fetch = function(options) {
} }
// get all remote branches and specify the dest / source pairs // get all remote branches and specify the dest / source pairs
var allBranchesOnRemote = this.origin.branchCollection.toArray(); var allBranchesOnRemote = this.origin.branchCollection.toArray();
var sourceDestPairs = _.map(allBranchesOnRemote, function(branch) { var sourceDestPairs = allBranchesOnRemote.map(function(branch) {
var branchName = branch.get('id'); var branchName = branch.get('id');
didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(branchName); didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(branchName);
@ -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,13 +1274,13 @@ 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,
pair.destination, pair.destination,
pair.source, pair.source,
_.extend( Object.assign(
{}, {},
options, options,
{dontThrowOnNoFetch: true} {dontThrowOnNoFetch: true}
@ -1309,14 +1305,14 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) {
// and remote master might be commits C2, C3, and C4, but we // and remote master might be commits C2, C3, and C4, but we
// might already have those commits. In this case, we don't need to // might already have those commits. In this case, we don't need to
// make them, so filter these out // make them, so filter these out
commitsToMake = _.filter(commitsToMake, function(commitJSON) { commitsToMake = commitsToMake.filter(function(commitJSON) {
return !this.refs[commitJSON.id]; return !this.refs[commitJSON.id];
}, this); }, this);
var makeCommit = function(id, parentIDs) { var makeCommit = function(id, parentIDs) {
// need to get the parents first. since we order by depth, we know // need to get the parents first. since we order by depth, we know
// the dependencies are there already // the dependencies are there already
var parents = _.map(parentIDs, function(parentID) { var parents = parentIDs.map(function(parentID) {
return this.refs[parentID]; return this.refs[parentID];
}, this); }, this);
return this.makeCommit(parents, id); return this.makeCommit(parents, id);
@ -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,
@ -1555,11 +1551,9 @@ GitEngine.prototype.fakeTeamwork = function(numToMake, branch) {
var deferred = Q.defer(); var deferred = Q.defer();
var chain = deferred.promise; var chain = deferred.promise;
_.each(_.range(numToMake), function(i) { for(var i = 0; i < numToMake; i++) {
chain = chain.then(function() { chain = chain.then(chainStep);
return chainStep(); }
});
});
this.animationQueue.thenFinish(chain, deferred); this.animationQueue.thenFinish(chain, deferred);
}; };
@ -1736,13 +1730,13 @@ 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);
var branchList = _.map(branchesToUpdate, function(val, id) { var branchList = branchesToUpdate.map(function(val, id) {
return id; return id;
}); });
return this.updateBranchesForHg(branchList); return this.updateBranchesForHg(branchList);
@ -1777,7 +1771,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
@ -1808,7 +1802,7 @@ GitEngine.prototype.updateBranchesForHg = function(branchList) {
GitEngine.prototype.updateCommitParentsForHgRebase = function(commitSet) { GitEngine.prototype.updateCommitParentsForHgRebase = function(commitSet) {
var anyChange = false; var anyChange = false;
_.each(commitSet, function(val, commitID) { Object.keys(commitSet).forEach(function(commitID) {
var commit = this.refs[commitID]; var commit = this.refs[commitID];
var thisUpdated = commit.checkForUpdatedParent(this); var thisUpdated = commit.checkForUpdatedParent(this);
anyChange = anyChange || thisUpdated; anyChange = anyChange || thisUpdated;
@ -1825,7 +1819,7 @@ GitEngine.prototype.pruneTree = function() {
var set = this.getUpstreamBranchSet(); var set = this.getUpstreamBranchSet();
// don't prune commits that HEAD depends on // don't prune commits that HEAD depends on
var headSet = Graph.getUpstreamSet(this, 'HEAD'); var headSet = Graph.getUpstreamSet(this, 'HEAD');
_.each(headSet, function(val, commitID) { Object.keys(headSet).forEach(function(commitID) {
set[commitID] = true; set[commitID] = true;
}); });
@ -1846,7 +1840,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 +1871,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 +1896,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
@ -2072,14 +2066,14 @@ GitEngine.prototype.hgRebase = function(destination, base) {
// and NOWWWwwww get all the descendants of this set // and NOWWWwwww get all the descendants of this set
var moreSets = []; var moreSets = [];
_.each(upstream, function(val, id) { Object.keys(upstream).forEach(function(id) {
moreSets.push(this.getDownstreamSet(id)); moreSets.push(this.getDownstreamSet(id));
}, this); }, this);
var masterSet = {}; var masterSet = {};
masterSet[baseCommit.get('id')] = true; masterSet[baseCommit.get('id')] = true;
_.each([upstream, downstream].concat(moreSets), function(set) { [upstream, downstream].concat(moreSets).forEach(function(set) {
_.each(set, function(val, id) { Object.keys(set).forEach(function(id) {
masterSet[id] = true; masterSet[id] = true;
}); });
}); });
@ -2087,16 +2081,14 @@ GitEngine.prototype.hgRebase = function(destination, base) {
// we also need the branches POINTING to master set // we also need the branches POINTING to master set
var branchMap = {}; var branchMap = {};
var upstreamSet = this.getUpstreamBranchSet(); var upstreamSet = this.getUpstreamBranchSet();
_.each(masterSet, function(val, commitID) { Object.keys(masterSet).forEach(function(commitID) {
// now loop over that commits branches // now loop over that commits branches
_.each(upstreamSet[commitID], function(branchJSON) { upstreamSet[commitID].forEach(function(branchJSON) {
branchMap[branchJSON.id] = true; branchMap[branchJSON.id] = true;
}); });
}); });
var branchList = _.map(branchMap, function(val, id) { var branchList = Object.keys(branchMap);
return id;
});
chain = chain.then(function() { chain = chain.then(function() {
// now we just moved a bunch of commits, but we haven't updated the // now we just moved a bunch of commits, but we haven't updated the
@ -2156,7 +2148,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 +2181,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 +2203,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 +2220,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 +2273,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!')
@ -2313,13 +2305,13 @@ GitEngine.prototype.filterRebaseCommits = function(
options options
) { ) {
var changesAlreadyMade = {}; var changesAlreadyMade = {};
_.each(stopSet, function(val, key) { Object.keys(stopSet).forEach(function(key) {
changesAlreadyMade[this.scrapeBaseID(key)] = true; changesAlreadyMade[this.scrapeBaseID(key)] = true;
}, this); }, this);
var uniqueIDs = {}; var uniqueIDs = {};
// resolve the commits we will rebase // resolve the commits we will rebase
return _.filter(toRebaseRough, function(commit) { return toRebaseRough.filter(function(commit) {
// no merge commits, unless we preserve // no merge commits, unless we preserve
if (commit.get('parents').length !== 1 && !options.preserveMerges) { if (commit.get('parents').length !== 1 && !options.preserveMerges) {
return false; return false;
@ -2344,7 +2336,7 @@ GitEngine.prototype.filterRebaseCommits = function(
GitEngine.prototype.getRebasePreserveMergesParents = function(oldCommit) { GitEngine.prototype.getRebasePreserveMergesParents = function(oldCommit) {
var oldParents = oldCommit.get('parents'); var oldParents = oldCommit.get('parents');
return _.map(oldParents, function(parent) { return oldParents.map(function(parent) {
var oldID = parent.get('id'); var oldID = parent.get('id');
var newID = this.getMostRecentBumpedID(oldID); var newID = this.getMostRecentBumpedID(oldID);
return this.refs[newID]; return this.refs[newID];
@ -2406,7 +2398,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 +2553,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 +2725,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 +2768,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 +2823,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 +3001,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 +3044,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 +3061,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);

View file

@ -1,5 +1,3 @@
var _ = require('underscore');
function invariant(truthy, reason) { function invariant(truthy, reason) {
if (!truthy) { if (!truthy) {
throw new Error(reason); throw new Error(reason);
@ -44,7 +42,7 @@ var Graph = {
if (type == 'HEAD') { if (type == 'HEAD') {
var headJSON = tree.HEAD; var headJSON = tree.HEAD;
var HEAD = new Ref(_.extend( var HEAD = new Ref(Object.assign(
tree.HEAD, tree.HEAD,
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target)
@ -57,7 +55,7 @@ var Graph = {
if (type == 'branch') { if (type == 'branch') {
var branchJSON = tree.branches[objID]; var branchJSON = tree.branches[objID];
var branch = new Branch(_.extend( var branch = new Branch(Object.assign(
tree.branches[objID], tree.branches[objID],
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target)
@ -70,7 +68,7 @@ var Graph = {
if (type == 'tag') { if (type == 'tag') {
var tagJSON = tree.tags[objID]; var tagJSON = tree.tags[objID];
var tag = new Tag(_.extend( var tag = new Tag(Object.assign(
tree.tags[objID], tree.tags[objID],
{ {
target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target) target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target)
@ -85,11 +83,11 @@ var Graph = {
var commitJSON = tree.commits[objID]; var commitJSON = tree.commits[objID];
var parentObjs = []; var parentObjs = [];
_.each(commitJSON.parents, function(parentID) { commitJSON.parents.forEach(function(parentID) {
parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID));
}, this); }, this);
var commit = new Commit(_.extend( var commit = new Commit(Object.assign(
commitJSON, commitJSON,
{ {
parents: parentObjs, parents: parentObjs,
@ -143,7 +141,7 @@ var Graph = {
var here = queue.pop(); var here = queue.pop();
var rents = here.get('parents'); var rents = here.get('parents');
_.each(rents, addToExplored); (rents || []).forEach(addToExplored);
} }
return exploredSet; return exploredSet;
}, },
@ -151,7 +149,7 @@ var Graph = {
getUniqueObjects: function(objects) { getUniqueObjects: function(objects) {
var unique = {}; var unique = {};
var result = []; var result = [];
_.forEach(objects, function(object) { objects.forEach(function(object) {
if (unique[object.id]) { if (unique[object.id]) {
return; return;
} }

View file

@ -92,7 +92,7 @@ TreeCompare.compareAllBranchesWithinTrees = function(treeA, treeB) {
treeA = this.convertTreeSafe(treeA); treeA = this.convertTreeSafe(treeA);
treeB = this.convertTreeSafe(treeB); treeB = this.convertTreeSafe(treeB);
var allBranches = _.extend( var allBranches = Object.assign(
{}, {},
treeA.branches, treeA.branches,
treeB.branches treeB.branches
@ -115,7 +115,7 @@ TreeCompare.compareAllTagsWithinTrees = function(treeA, treeB) {
TreeCompare.compareBranchesWithinTrees = function(treeA, treeB, branches) { TreeCompare.compareBranchesWithinTrees = function(treeA, treeB, branches) {
var result = true; var result = true;
_.each(branches, function(branchName) { branches.forEach(function(branchName) {
result = result && this.compareBranchWithinTrees(treeA, treeB, branchName); result = result && this.compareBranchWithinTrees(treeA, treeB, branchName);
}, this); }, this);
@ -140,13 +140,12 @@ TreeCompare.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) {
treeB = this.convertTreeSafe(treeB); treeB = this.convertTreeSafe(treeB);
this.reduceTreeFields([treeA, treeB]); this.reduceTreeFields([treeA, treeB]);
var allBranches = _.extend( var allBranches = Object.assign(
{}, {},
treeA.branches, treeA.branches,
treeB.branches treeB.branches
); );
var branchNames = []; var branchNames = Object.keys(allBranches || {});
_.each(allBranches, function(obj, name) { branchNames.push(name); });
return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames); return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames);
}; };
@ -165,8 +164,8 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran
} }
// don't mess up the rest of comparison // don't mess up the rest of comparison
branchA = _.clone(branchA); branchA = Object.assign({}, branchA);
branchB = _.clone(branchB); branchB = Object.assign({}, branchB);
branchA.target = this.getBaseRef(branchA.target); branchA.target = this.getBaseRef(branchA.target);
branchB.target = this.getBaseRef(branchB.target); branchB.target = this.getBaseRef(branchB.target);
@ -176,7 +175,7 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran
var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB); var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB);
var result = true; var result = true;
_.each(branches, function(branchName) { branches.forEach(function(branchName) {
var branchA = treeA.branches[branchName]; var branchA = treeA.branches[branchName];
var branchB = treeB.branches[branchName]; var branchB = treeB.branches[branchName];
@ -188,7 +187,8 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran
TreeCompare.evalAsserts = function(tree, assertsPerBranch) { TreeCompare.evalAsserts = function(tree, assertsPerBranch) {
var result = true; var result = true;
_.each(assertsPerBranch, function(asserts, branchName) { Object.keys(assertsPerBranch).forEach(function(branchName) {
var asserts = assertsPerBranch[branchName];
result = result && this.evalAssertsOnBranch(tree, branchName, asserts); result = result && this.evalAssertsOnBranch(tree, branchName, asserts);
}, this); }, this);
return result; return result;
@ -217,7 +217,7 @@ TreeCompare.evalAssertsOnBranch = function(tree, branchName, asserts) {
} }
var result = true; var result = true;
_.each(asserts, function(assert) { asserts.forEach(function(assert) {
try { try {
result = result && assert(data); result = result && assert(data);
} catch (err) { } catch (err) {
@ -270,7 +270,7 @@ TreeCompare.getRecurseCompareHashAgnostic = function(treeA, treeB) {
// some buildup functions // some buildup functions
var getStrippedCommitCopy = function(commit) { var getStrippedCommitCopy = function(commit) {
if (!commit) { return {}; } if (!commit) { return {}; }
return _.extend( return Object.assign(
{}, {},
commit, commit,
{ {
@ -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 // 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 // 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); 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 pAid = commitA.parents[index];
var pBid = commitB.parents[index]; var pBid = commitB.parents[index];
@ -315,7 +315,7 @@ TreeCompare.getRecurseCompare = function(treeA, treeB, options) {
var childB = treeB.commits[pBid]; var childB = treeB.commits[pBid];
result = result && recurseCompare(childA, childB); result = result && recurseCompare(childA, childB);
}, this); }
// if each of our children recursively are equal, we are good // if each of our children recursively are equal, we are good
return result; return result;
}; };
@ -327,9 +327,10 @@ TreeCompare.lowercaseTree = function(tree) {
tree.HEAD.target = tree.HEAD.target.toLocaleLowerCase(); tree.HEAD.target = tree.HEAD.target.toLocaleLowerCase();
} }
var branches = tree.branches; var branches = tree.branches || {};
tree.branches = {}; tree.branches = {};
_.each(branches, function(obj, name) { Object.keys(branches).forEach(function(name) {
var obj = branches[name];
obj.id = obj.id.toLocaleLowerCase(); obj.id = obj.id.toLocaleLowerCase();
tree.branches[name.toLocaleLowerCase()] = obj; tree.branches[name.toLocaleLowerCase()] = obj;
}); });
@ -377,8 +378,9 @@ TreeCompare.reduceTreeFields = function(trees) {
tags: {} tags: {}
}; };
_.each(trees, function(tree) { trees.forEach(function(tree) {
_.each(treeDefaults, function(val, key) { Object.keys(treeDefaults).forEach(function(key) {
var val = treeDefaults[key];
if (tree[key] === undefined) { if (tree[key] === undefined) {
tree[key] = val; tree[key] = val;
} }
@ -388,10 +390,11 @@ TreeCompare.reduceTreeFields = function(trees) {
// this function saves only the specified fields of a tree // this function saves only the specified fields of a tree
var saveOnly = function(tree, treeKey, saveFields, sortFields) { var saveOnly = function(tree, treeKey, saveFields, sortFields) {
var objects = tree[treeKey]; var objects = tree[treeKey];
_.each(objects, function(obj, objKey) { Object.keys(objects).forEach(function(objKey) {
var obj = objects[objKey];
// our blank slate to copy over // our blank slate to copy over
var blank = {}; var blank = {};
_.each(saveFields, function(field) { saveFields.forEach(function(field) {
if (obj[field] !== undefined) { if (obj[field] !== undefined) {
blank[field] = obj[field]; blank[field] = obj[field];
} else if (defaults[field] !== undefined) { } else if (defaults[field] !== undefined) {
@ -399,7 +402,7 @@ TreeCompare.reduceTreeFields = function(trees) {
} }
}); });
_.each(sortFields, function(field) { Object.values(sortFields || {}).forEach(function(field) {
// also sort some fields // also sort some fields
if (obj[field]) { if (obj[field]) {
obj[field].sort(); obj[field].sort();
@ -410,7 +413,7 @@ TreeCompare.reduceTreeFields = function(trees) {
}); });
}; };
_.each(trees, function(tree) { trees.forEach(function(tree) {
saveOnly(tree, 'commits', commitSaveFields, commitSortFields); saveOnly(tree, 'commits', commitSaveFields, commitSortFields);
saveOnly(tree, 'branches', branchSaveFields); saveOnly(tree, 'branches', branchSaveFields);
saveOnly(tree, 'tags', tagSaveFields); saveOnly(tree, 'tags', tagSaveFields);

View file

@ -11,7 +11,7 @@ var fallbackMap = {
// lets change underscores template settings so it interpolates // lets change underscores template settings so it interpolates
// things like "{branchName} does not exist". // things like "{branchName} does not exist".
var templateSettings = _.clone(_.templateSettings); var templateSettings = Object.assign({}, _.templateSettings);
templateSettings.interpolate = /\{(.+?)\}/g; templateSettings.interpolate = /\{(.+?)\}/g;
var template = exports.template = function(str, params) { var template = exports.template = function(str, params) {
return _.template(str, params, templateSettings); return _.template(str, params, templateSettings);
@ -106,7 +106,8 @@ exports.getStartDialog = function(level) {
markdown: str('error-untranslated') markdown: str('error-untranslated')
} }
}; };
var startCopy = _.clone( var startCopy = Object.assign(
{},
level.startDialog[getDefaultLocale()] || level.startDialog level.startDialog[getDefaultLocale()] || level.startDialog
); );
startCopy.childViews.unshift(errorAlert); startCopy.childViews.unshift(errorAlert);

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Q = require('q'); var Q = require('q');
@ -360,7 +359,7 @@ var LevelBuilder = Level.extend({
}, },
getExportObj: function() { getExportObj: function() {
var compiledLevel = _.extend( var compiledLevel = Object.assign(
{}, {},
this.level this.level
); );

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Q = require('q'); var Q = require('q');
var util = require('../util'); var util = require('../util');
@ -70,7 +69,7 @@ var Level = Sandbox.extend({
// if there is a multiview in the beginning, open that // if there is a multiview in the beginning, open that
// and let it resolve our deferred // and let it resolve our deferred
if (this.level.startDialog && !this.testOption('noIntroDialog')) { if (this.level.startDialog && !this.testOption('noIntroDialog')) {
new MultiView(_.extend( new MultiView(Object.assign(
{}, {},
intl.getStartDialog(this.level), intl.getStartDialog(this.level),
{ deferred: deferred } { deferred: deferred }
@ -99,7 +98,7 @@ var Level = Sandbox.extend({
var dialog = $.extend({}, intl.getStartDialog(levelObj)); var dialog = $.extend({}, intl.getStartDialog(levelObj));
// grab the last slide only // grab the last slide only
dialog.childViews = dialog.childViews.slice(-1); dialog.childViews = dialog.childViews.slice(-1);
new MultiView(_.extend( new MultiView(Object.assign(
dialog, dialog,
{ deferred: deferred } { deferred: deferred }
)); ));
@ -406,8 +405,9 @@ var Level = Sandbox.extend({
} }
var matched = false; var matched = false;
_.each(Commands.commands.getCommandsThatCount(), function(map) { var commandsThatCount = Commands.commands.getCommandsThatCount();
_.each(map, function(regex) { Object.values(commandsThatCount).forEach(function(map) {
Object.values(map).forEach(function(regex) {
matched = matched || regex.test(command.get('rawStr')); matched = matched || regex.test(command.get('rawStr'));
}); });
}); });

View file

@ -1,5 +1,3 @@
var _ = require('underscore');
var GitCommands = require('../git/commands'); var GitCommands = require('../git/commands');
var Commands = require('../commands'); var Commands = require('../commands');
var SandboxCommands = require('../sandbox/commands'); var SandboxCommands = require('../sandbox/commands');
@ -68,15 +66,17 @@ ParseWaterfall.prototype.addLast = function(which, value) {
}; };
ParseWaterfall.prototype.expandAllShortcuts = function(commandStr) { ParseWaterfall.prototype.expandAllShortcuts = function(commandStr) {
_.each(this.shortcutWaterfall, function(shortcutMap) { this.shortcutWaterfall.forEach(function(shortcutMap) {
commandStr = this.expandShortcut(commandStr, shortcutMap); commandStr = this.expandShortcut(commandStr, shortcutMap);
}, this); }, this);
return commandStr; return commandStr;
}; };
ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) { ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) {
_.each(shortcutMap, function(map, vcs) { Object.keys(shortcutMap).forEach(function(vcs) {
_.each(map, function(regex, method) { var map = shortcutMap[vcs];
Object.keys(map).forEach(function(method) {
var regex = map[method];
var results = regex.exec(commandStr); var results = regex.exec(commandStr);
if (results) { if (results) {
commandStr = vcs + ' ' + method + ' ' + commandStr.slice(results[0].length); commandStr = vcs + ' ' + method + ' ' + commandStr.slice(results[0].length);
@ -87,13 +87,13 @@ ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) {
}; };
ParseWaterfall.prototype.processAllInstants = function(commandStr) { ParseWaterfall.prototype.processAllInstants = function(commandStr) {
_.each(this.instantWaterfall, function(instantCommands) { this.instantWaterfall.forEach(function(instantCommands) {
this.processInstant(commandStr, instantCommands); this.processInstant(commandStr, instantCommands);
}, this); }, this);
}; };
ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands) { ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands) {
_.each(instantCommands, function(tuple) { instantCommands.forEach(function(tuple) {
var regex = tuple[0]; var regex = tuple[0];
var results = regex.exec(commandStr); var results = regex.exec(commandStr);
if (results) { if (results) {
@ -109,7 +109,7 @@ ParseWaterfall.prototype.parseAll = function(commandStr) {
} }
var toReturn = false; var toReturn = false;
_.each(this.parseWaterfall, function(parseFunc) { this.parseWaterfall.forEach(function(parseFunc) {
var results = parseFunc(commandStr); var results = parseFunc(commandStr);
if (results) { if (results) {
toReturn = results; toReturn = results;
@ -120,4 +120,3 @@ ParseWaterfall.prototype.parseAll = function(commandStr) {
}; };
exports.ParseWaterfall = ParseWaterfall; exports.ParseWaterfall = ParseWaterfall;

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Errors = require('../util/errors'); var Errors = require('../util/errors');
@ -78,12 +77,13 @@ var Command = Backbone.Model.extend({
var generalArgs = this.getGeneralArgs(); var generalArgs = this.getGeneralArgs();
var options = this.getOptionsMap(); var options = this.getOptionsMap();
generalArgs = _.map(generalArgs, function(arg) { generalArgs = generalArgs.map(function(arg) {
return this.replaceDotWithHead(arg); return this.replaceDotWithHead(arg);
}, this); }, this);
var newMap = {}; var newMap = {};
_.each(options, function(args, key) { Object.keys(options).forEach(function(key) {
newMap[key] = _.map(args, function(arg) { var args = options[key];
newMap[key] = Object.values(args).map(function (arg) {
return this.replaceDotWithHead(arg); return this.replaceDotWithHead(arg);
}, this); }, this);
}, this); }, this);
@ -93,7 +93,7 @@ var Command = Backbone.Model.extend({
deleteOptions: function(options) { deleteOptions: function(options) {
var map = this.getOptionsMap(); var map = this.getOptionsMap();
_.each(options, function(option) { options.forEach(function(option) {
delete map[option]; delete map[option];
}, this); }, this);
this.setOptionsMap(map); this.setOptionsMap(map);
@ -273,7 +273,8 @@ var Command = Backbone.Model.extend({
return false; return false;
} }
_.each(results.toSet, function(obj, key) { Object.keys(results.toSet).forEach(function(key) {
var obj = results.toSet[key];
// data comes back from the parsing functions like // data comes back from the parsing functions like
// options (etc) that need to be set // options (etc) that need to be set
this.set(key, obj); this.set(key, obj);

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var util = require('../util'); var util = require('../util');
var constants = require('../util/constants'); var constants = require('../util/constants');
@ -98,7 +97,7 @@ var instantCommands = [
intl.str('show-all-commands'), intl.str('show-all-commands'),
'<br/>' '<br/>'
]; ];
_.each(allCommands, function(regex, command) { allCommands.forEach(function(regex, command) {
lines.push(command); lines.push(command);
}); });
@ -134,17 +133,20 @@ var getAllCommands = function() {
'mobileAlert' 'mobileAlert'
]; ];
var allCommands = _.extend( var allCommands = Object.assign(
{}, {},
require('../level').regexMap, require('../level').regexMap,
regexMap regexMap
); );
_.each(Commands.commands.getRegexMap(), function(map, vcs) { var mRegexMap = Commands.commands.getRegexMap();
_.each(map, function(regex, method) { Object.keys(mRegexMap).forEach(function(vcs) {
var map = mRegexMap[vcs];
Object.keys(map).forEach(function(method) {
var regex = map[method];
allCommands[vcs + ' ' + method] = regex; allCommands[vcs + ' ' + method] = regex;
}); });
}); });
_.each(toDelete, function(key) { toDelete.forEach(function(key) {
delete allCommands[key]; delete allCommands[key];
}); });

View file

@ -41,7 +41,7 @@ var validateLevel = function(level) {
'solutionCommand' 'solutionCommand'
]; ];
_.each(requiredFields, function(field) { requiredFields.forEach(function(field) {
if (level[field] === undefined) { if (level[field] === undefined) {
console.log(level); console.log(level);
throw new Error('I need this field for a level: ' + field); throw new Error('I need this field for a level: ' + field);
@ -52,14 +52,15 @@ var validateLevel = function(level) {
/** /**
* Unpack the level sequences. * Unpack the level sequences.
*/ */
_.each(levelSequences, function(levels, levelSequenceName) { Object.keys(levelSequences).forEach(function(levelSequenceName) {
var levels = levelSequences[levelSequenceName];
_sequences.push(levelSequenceName); _sequences.push(levelSequenceName);
if (!levels || !levels.length) { if (!levels || !levels.length) {
throw new Error('no empty sequences allowed'); throw new Error('no empty sequences allowed');
} }
// for this particular sequence... // for this particular sequence...
_.each(levels, function(level, index) { levels.forEach(function(level, index) {
validateLevel(level); validateLevel(level);
var id = levelSequenceName + String(index + 1); var id = levelSequenceName + String(index + 1);
@ -89,7 +90,7 @@ AppConstants.StoreSubscribePrototype,
}, },
getSequences: function() { getSequences: function() {
return _.keys(levelSequences); return Object.keys(levelSequences);
}, },
getLevelsInSequence: function(sequenceName) { getLevelsInSequence: function(sequenceName) {

View file

@ -179,7 +179,7 @@ var DemonstrationBuilder = ContainedBase.extend({
this.deferred = options.deferred || Q.defer(); this.deferred = options.deferred || Q.defer();
if (options.fromObj) { if (options.fromObj) {
var toEdit = options.fromObj.options; var toEdit = options.fromObj.options;
options = _.extend( options = Object.assign(
{}, {},
options, options,
toEdit, toEdit,
@ -295,7 +295,7 @@ var MultiViewBuilder = ContainedBase.extend({
this.JSON = { this.JSON = {
views: this.getChildViews(), views: this.getChildViews(),
supportedViews: _.keys(this.typeToConstructor) supportedViews: Object.keys(this.typeToConstructor)
}; };
this.container = new ModalTerminal({ this.container = new ModalTerminal({
@ -416,4 +416,3 @@ exports.DemonstrationBuilder = DemonstrationBuilder;
exports.TextGrabber = TextGrabber; exports.TextGrabber = TextGrabber;
exports.MultiViewBuilder = MultiViewBuilder; exports.MultiViewBuilder = MultiViewBuilder;
exports.MarkdownPresenter = MarkdownPresenter; exports.MarkdownPresenter = MarkdownPresenter;

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Main = require('../app'); var Main = require('../app');
@ -173,7 +172,7 @@ var CommandPromptView = Backbone.View.extend({
which.reverse(); which.reverse();
var str = ''; var str = '';
_.each(which, function(text) { which.forEach(function(text) {
str += text + ';'; str += text + ';';
}, this); }, this);
@ -202,4 +201,3 @@ var CommandPromptView = Backbone.View.extend({
}); });
exports.CommandPromptView = CommandPromptView; exports.CommandPromptView = CommandPromptView;

View file

@ -25,7 +25,7 @@ var GitDemonstrationView = ContainedBase.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
this.options = options; this.options = options;
this.JSON = _.extend( this.JSON = Object.assign(
{ {
beforeMarkdowns: [ beforeMarkdowns: [
'## Git Commits', '## Git Commits',
@ -55,7 +55,7 @@ var GitDemonstrationView = ContainedBase.extend({
this.render(); this.render();
this.checkScroll(); this.checkScroll();
this.navEvents = _.clone(Backbone.Events); this.navEvents = Object.assign({}, Backbone.Events);
this.navEvents.on('positive', this.positive, this); this.navEvents.on('positive', this.positive, this);
this.navEvents.on('negative', this.negative, this); this.navEvents.on('negative', this.negative, this);
this.keyboardListener = new KeyboardListener({ this.keyboardListener = new KeyboardListener({
@ -83,9 +83,9 @@ var GitDemonstrationView = ContainedBase.extend({
}, },
checkScroll: function() { checkScroll: function() {
var children = this.$('div.demonstrationText').children(); var children = this.$('div.demonstrationText').children().toArray();
var heights = _.map(children, function(child) { return child.clientHeight; }); var heights = children.map(function(child) { return child.clientHeight; });
var totalHeight = _.reduce(heights, function(a, b) { return a + b; }); var totalHeight = heights.reduce(function(a, b) { return a + b; });
if (totalHeight < this.$('div.demonstrationText').height()) { if (totalHeight < this.$('div.demonstrationText').height()) {
this.$('div.demonstrationText').addClass('noLongText'); this.$('div.demonstrationText').addClass('noLongText');
} }
@ -168,7 +168,7 @@ var GitDemonstrationView = ContainedBase.extend({
var chainDeferred = Q.defer(); var chainDeferred = Q.defer();
var chainPromise = chainDeferred.promise; var chainPromise = chainDeferred.promise;
_.each(commands, function(command, index) { commands.forEach(function(command, index) {
chainPromise = chainPromise.then(function() { chainPromise = chainPromise.then(function() {
var myDefer = Q.defer(); var myDefer = Q.defer();
this.mainVis.gitEngine.dispatch(command, myDefer); this.mainVis.gitEngine.dispatch(command, myDefer);
@ -244,4 +244,3 @@ var GitDemonstrationView = ContainedBase.extend({
}); });
exports.GitDemonstrationView = GitDemonstrationView; exports.GitDemonstrationView = GitDemonstrationView;

View file

@ -86,7 +86,7 @@ var GeneralButton = ContainedBase.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
this.navEvents = options.navEvents || _.clone(Backbone.Events); this.navEvents = options.navEvents || Object.assign({}, Backbone.Events);
this.destination = options.destination; this.destination = options.destination;
if (!this.destination) { if (!this.destination) {
this.container = new ModalTerminal(); this.container = new ModalTerminal();
@ -160,7 +160,7 @@ var LeftRightView = PositiveNegativeBase.extend({
// events system to add support for git demonstration view taking control of the // events system to add support for git demonstration view taking control of the
// click events // click events
this.pipeEvents = options.events; this.pipeEvents = options.events;
this.navEvents = _.clone(Backbone.Events); this.navEvents = Object.assign({}, Backbone.Events);
this.JSON = { this.JSON = {
showLeft: (options.showLeft === undefined) ? true : options.showLeft, showLeft: (options.showLeft === undefined) ? true : options.showLeft,
@ -305,7 +305,7 @@ var ModalTerminal = ContainedBase.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
this.navEvents = options.events || _.clone(Backbone.Events); this.navEvents = options.events || Object.assign({}, Backbone.Events);
this.container = new ModalView(); this.container = new ModalView();
this.JSON = { this.JSON = {
@ -372,7 +372,7 @@ var ConfirmCancelTerminal = Backbone.View.extend({
options = options || {}; options = options || {};
this.deferred = options.deferred || Q.defer(); this.deferred = options.deferred || Q.defer();
this.modalAlert = new ModalAlert(_.extend( this.modalAlert = new ModalAlert(Object.assign(
{}, {},
{ markdown: '#you sure?' }, { markdown: '#you sure?' },
options options
@ -395,7 +395,7 @@ var ConfirmCancelTerminal = Backbone.View.extend({
}.bind(this)); }.bind(this));
// also setup keyboard // also setup keyboard
this.navEvents = _.clone(Backbone.Events); this.navEvents = Object.assign({}, Backbone.Events);
this.navEvents.on('positive', this.positive, this); this.navEvents.on('positive', this.positive, this);
this.navEvents.on('negative', this.negative, this); this.navEvents.on('negative', this.negative, this);
this.keyboardListener = new KeyboardListener({ this.keyboardListener = new KeyboardListener({
@ -470,7 +470,7 @@ var NextLevelConfirm = ConfirmCancelTerminal.extend({
'</p>'; '</p>';
} }
options = _.extend( options = Object.assign(
{}, {},
options, options,
{ {

View file

@ -40,7 +40,7 @@ var LevelDropdownView = ContainedBase.extend({
}] }]
}; };
this.navEvents = _.clone(Backbone.Events); this.navEvents = Object.assign({}, Backbone.Events);
this.navEvents.on('clickedID', _.debounce( this.navEvents.on('clickedID', _.debounce(
this.loadLevelID.bind(this), this.loadLevelID.bind(this),
300, 300,
@ -211,7 +211,7 @@ var LevelDropdownView = ContainedBase.extend({
}, },
getTabIndex: function() { getTabIndex: function() {
var ids = _.map(this.JSON.tabs, function(tab) { var ids = this.JSON.tabs.map(function(tab) {
return tab.id; return tab.id;
}); });
return ids.indexOf(this.JSON.selectedTab); return ids.indexOf(this.JSON.selectedTab);
@ -235,7 +235,7 @@ var LevelDropdownView = ContainedBase.extend({
}, },
getSequencesOnTab: function() { getSequencesOnTab: function() {
return _.filter(this.sequences, function(sequenceName) { return this.sequences.filter(function(sequenceName) {
var tab = LEVELS.getTabForSequence(sequenceName); var tab = LEVELS.getTabForSequence(sequenceName);
return tab === this.JSON.selectedTab; return tab === this.JSON.selectedTab;
}, this); }, this);
@ -292,7 +292,7 @@ var LevelDropdownView = ContainedBase.extend({
$(selector).toggleClass('selected', value); $(selector).toggleClass('selected', value);
// also go find the series and update the about // 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) { if (view.levelIDs.indexOf(id) === -1) {
return; return;
} }
@ -343,14 +343,14 @@ var LevelDropdownView = ContainedBase.extend({
}, },
updateSolvedStatus: function() { updateSolvedStatus: function() {
_.each(this.seriesViews, function(view) { this.seriesViews.forEach(function(view) {
view.updateSolvedStatus(); view.updateSolvedStatus();
}, this); }, this);
}, },
buildSequences: function() { buildSequences: function() {
this.seriesViews = []; this.seriesViews = [];
_.each(this.getSequencesOnTab(), function(sequenceName) { this.getSequencesOnTab().forEach(function(sequenceName) {
this.seriesViews.push(new SeriesView({ this.seriesViews.push(new SeriesView({
destination: this.$el, destination: this.$el,
name: sequenceName, name: sequenceName,
@ -377,7 +377,7 @@ var SeriesView = BaseView.extend({
this.levelIDs = []; this.levelIDs = [];
var firstLevelInfo = null; var firstLevelInfo = null;
_.each(this.levels, function(level) { this.levels.forEach(function(level) {
if (firstLevelInfo === null) { if (firstLevelInfo === null) {
firstLevelInfo = this.formatLevelAbout(level.id); firstLevelInfo = this.formatLevelAbout(level.id);
} }
@ -444,4 +444,3 @@ var SeriesView = BaseView.extend({
}); });
exports.LevelDropdownView = LevelDropdownView; exports.LevelDropdownView = LevelDropdownView;

View file

@ -48,7 +48,7 @@ var MultiView = Backbone.View.extend({
this.childViews = []; this.childViews = [];
this.currentIndex = 0; this.currentIndex = 0;
this.navEvents = _.clone(Backbone.Events); this.navEvents = Object.assign({}, Backbone.Events);
this.navEvents.on('negative', this.getNegFunc(), this); this.navEvents.on('negative', this.getNegFunc(), this);
this.navEvents.on('positive', this.getPosFunc(), this); this.navEvents.on('positive', this.getPosFunc(), this);
this.navEvents.on('quit', this.finish, this); this.navEvents.on('quit', this.finish, this);
@ -142,7 +142,7 @@ var MultiView = Backbone.View.extend({
// other views will take if they need to // other views will take if they need to
this.keyboardListener.mute(); this.keyboardListener.mute();
_.each(this.childViews, function(childView) { this.childViews.forEach(function(childView) {
childView.die(); childView.die();
}); });
@ -159,7 +159,7 @@ var MultiView = Backbone.View.extend({
if (!this.typeToConstructor[type]) { if (!this.typeToConstructor[type]) {
throw new Error('no constructor for type "' + type + '"'); throw new Error('no constructor for type "' + type + '"');
} }
var view = new this.typeToConstructor[type](_.extend( var view = new this.typeToConstructor[type](Object.assign(
{}, {},
viewJSON.options, viewJSON.options,
{ wait: true } { wait: true }
@ -183,7 +183,7 @@ var MultiView = Backbone.View.extend({
render: function() { render: function() {
// go through each and render... show the first // 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); var childView = this.createChildView(childViewJSON);
this.childViews.push(childView); this.childViews.push(childView);
this.addNavToView(childView, index); this.addNavToView(childView, index);
@ -192,4 +192,3 @@ var MultiView = Backbone.View.extend({
}); });
exports.MultiView = MultiView; exports.MultiView = MultiView;

View file

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

View file

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

View file

@ -1,9 +1,8 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var VisBase = Backbone.Model.extend({ var VisBase = Backbone.Model.extend({
removeKeys: function(keys) { removeKeys: function(keys) {
_.each(keys, function(key) { keys.forEach(function(key) {
if (this.get(key)) { if (this.get(key)) {
this.get(key).remove(); this.get(key).remove();
} }
@ -13,7 +12,7 @@ var VisBase = Backbone.Model.extend({
animateAttrKeys: function(keys, attrObj, speed, easing) { animateAttrKeys: function(keys, attrObj, speed, easing) {
// either we animate a specific subset of keys or all // either we animate a specific subset of keys or all
// possible things we could animate // possible things we could animate
keys = _.extend( keys = Object.assign(
{}, {},
{ {
include: ['circle', 'arrow', 'rect', 'path', 'text'], include: ['circle', 'arrow', 'rect', 'path', 'text'],
@ -25,15 +24,15 @@ var VisBase = Backbone.Model.extend({
var attr = this.getAttributes(); var attr = this.getAttributes();
// safely insert this attribute into all the keys we want // safely insert this attribute into all the keys we want
_.each(keys.include, function(key) { keys.include.forEach(function(key) {
attr[key] = _.extend( attr[key] = Object.assign(
{}, {},
attr[key], attr[key],
attrObj attrObj
); );
}); });
_.each(keys.exclude, function(key) { keys.exclude.forEach(function(key) {
delete attr[key]; delete attr[key];
}); });
@ -42,4 +41,3 @@ var VisBase = Backbone.Model.extend({
}); });
exports.VisBase = VisBase; exports.VisBase = VisBase;

View file

@ -1,9 +1,8 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var VisBase = Backbone.Model.extend({ var VisBase = Backbone.Model.extend({
removeKeys: function(keys) { removeKeys: function(keys) {
_.each(keys, function(key) { keys.forEach(function(key) {
if (this.get(key)) { if (this.get(key)) {
this.get(key).remove(); this.get(key).remove();
} }
@ -35,14 +34,14 @@ var VisBase = Backbone.Model.extend({
}, },
setAttrBase: function(keys, attr, instant, speed, easing) { setAttrBase: function(keys, attr, instant, speed, easing) {
_.each(keys, function(key) { keys.forEach(function(key) {
if (instant) { if (instant) {
this.get(key).attr(attr[key]); this.get(key).attr(attr[key]);
} else { } else {
this.get(key).stop(); this.get(key).stop();
this.get(key).animate(attr[key], speed, easing); this.get(key).animate(attr[key], speed, easing);
// some keys don't support animating too, so set those instantly here // 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) { if (attr[key] && attr[key][nonAnimateKey] !== undefined) {
this.get(key).attr(nonAnimateKey, attr[key][nonAnimateKey]); this.get(key).attr(nonAnimateKey, attr[key][nonAnimateKey]);
} }
@ -58,7 +57,7 @@ var VisBase = Backbone.Model.extend({
animateAttrKeys: function(keys, attrObj, speed, easing) { animateAttrKeys: function(keys, attrObj, speed, easing) {
// either we animate a specific subset of keys or all // either we animate a specific subset of keys or all
// possible things we could animate // possible things we could animate
keys = _.extend( keys = Object.assign(
{}, {},
{ {
include: ['circle', 'arrow', 'rect', 'path', 'text'], include: ['circle', 'arrow', 'rect', 'path', 'text'],
@ -70,15 +69,15 @@ var VisBase = Backbone.Model.extend({
var attr = this.getAttributes(); var attr = this.getAttributes();
// safely insert this attribute into all the keys we want // safely insert this attribute into all the keys we want
_.each(keys.include, function(key) { keys.include.forEach(function(key) {
attr[key] = _.extend( attr[key] = Object.assign(
{}, {},
attr[key], attr[key],
attrObj attrObj
); );
}); });
_.each(keys.exclude, function(key) { keys.exclude.forEach(function(key) {
delete attr[key]; delete attr[key];
}); });
@ -87,4 +86,3 @@ var VisBase = Backbone.Model.extend({
}); });
exports.VisBase = VisBase; exports.VisBase = VisBase;

View file

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

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var GRAPHICS = require('../util/constants').GRAPHICS; var GRAPHICS = require('../util/constants').GRAPHICS;
@ -15,7 +14,7 @@ var VisEdge = VisBase.extend({
validateAtInit: function() { validateAtInit: function() {
var required = ['tail', 'head']; var required = ['tail', 'head'];
_.each(required, function(key) { required.forEach(function(key) {
if (!this.get(key)) { if (!this.get(key)) {
throw new Error(key + ' is required!'); throw new Error(key + ' is required!');
} }

View file

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

View file

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

View file

@ -1,4 +1,3 @@
var _ = require('underscore');
var Backbone = require('backbone'); var Backbone = require('backbone');
var Collections = require('../models/collections'); var Collections = require('../models/collections');
@ -13,7 +12,7 @@ var Visualization = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
options = options || {}; options = options || {};
this.options = options; this.options = options;
this.customEvents = _.clone(Backbone.Events); this.customEvents = Object.assign({}, Backbone.Events);
this.containerElement = options.containerElement; this.containerElement = options.containerElement;
var _this = this; var _this = this;
@ -104,7 +103,7 @@ var Visualization = Backbone.View.extend({
makeOrigin: function(options) { makeOrigin: function(options) {
// oh god, here we go. We basically do a bizarre form of composition here, // oh god, here we go. We basically do a bizarre form of composition here,
// where this visualization actually contains another one of itself. // where this visualization actually contains another one of itself.
this.originVis = new Visualization(_.extend( this.originVis = new Visualization(Object.assign(
{}, {},
// copy all of our options over, except... // copy all of our options over, except...
this.options, this.options,