From 052aa1e299852df4404a1cfb7fd1d11752037d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 06:07:06 +0700 Subject: [PATCH 01/13] change '_.extend' to 'Object.assign' --- src/js/git/index.js | 12 ++++++------ src/js/graph/index.js | 8 ++++---- src/js/graph/treeCompare.js | 6 +++--- src/js/level/builder.js | 2 +- src/js/level/index.js | 4 ++-- src/js/sandbox/commands.js | 2 +- src/js/views/builderViews.js | 2 +- src/js/views/gitDemonstrationView.js | 2 +- src/js/views/index.js | 4 ++-- src/js/views/multiView.js | 2 +- src/js/visuals/tree.js | 4 ++-- src/js/visuals/visBase.js | 4 ++-- src/js/visuals/visualization.js | 2 +- 13 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/js/git/index.js b/src/js/git/index.js index 2825a96a..7754f2ae 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -518,7 +518,7 @@ GitEngine.prototype.getOrMakeRecursive = function( if (type == 'HEAD') { var headJSON = tree.HEAD; - var HEAD = new Ref(_.extend( + var HEAD = new Ref(Object.assign( tree.HEAD, { target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target) @@ -531,7 +531,7 @@ GitEngine.prototype.getOrMakeRecursive = function( if (type == 'branch') { var branchJSON = tree.branches[objID]; - var branch = new Branch(_.extend( + var branch = new Branch(Object.assign( tree.branches[objID], { target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target) @@ -544,7 +544,7 @@ GitEngine.prototype.getOrMakeRecursive = function( if (type == 'tag') { var tagJSON = tree.tags[objID]; - var tag = new Tag(_.extend( + var tag = new Tag(Object.assign( tree.tags[objID], { target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target) @@ -563,7 +563,7 @@ GitEngine.prototype.getOrMakeRecursive = function( parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); }, this); - var commit = new Commit(_.extend( + var commit = new Commit(Object.assign( commitJSON, { parents: parentObjs, @@ -846,7 +846,7 @@ GitEngine.prototype.makeCommit = function(parents, id, options) { id = this.getUniqueID(); } - var commit = new Commit(_.extend({ + var commit = new Commit(Object.assign({ parents: parents, id: id, gitVisuals: this.gitVisuals @@ -1284,7 +1284,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { this.origin, pair.destination, pair.source, - _.extend( + Object.assign( {}, options, {dontThrowOnNoFetch: true} diff --git a/src/js/graph/index.js b/src/js/graph/index.js index 49285de0..ed2c0745 100644 --- a/src/js/graph/index.js +++ b/src/js/graph/index.js @@ -44,7 +44,7 @@ var Graph = { if (type == 'HEAD') { var headJSON = tree.HEAD; - var HEAD = new Ref(_.extend( + var HEAD = new Ref(Object.assign( tree.HEAD, { target: this.getOrMakeRecursive(tree, createdSoFar, headJSON.target) @@ -57,7 +57,7 @@ var Graph = { if (type == 'branch') { var branchJSON = tree.branches[objID]; - var branch = new Branch(_.extend( + var branch = new Branch(Object.assign( tree.branches[objID], { target: this.getOrMakeRecursive(tree, createdSoFar, branchJSON.target) @@ -70,7 +70,7 @@ var Graph = { if (type == 'tag') { var tagJSON = tree.tags[objID]; - var tag = new Tag(_.extend( + var tag = new Tag(Object.assign( tree.tags[objID], { target: this.getOrMakeRecursive(tree, createdSoFar, tagJSON.target) @@ -89,7 +89,7 @@ var Graph = { parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); }, this); - var commit = new Commit(_.extend( + var commit = new Commit(Object.assign( commitJSON, { parents: parentObjs, diff --git a/src/js/graph/treeCompare.js b/src/js/graph/treeCompare.js index 132782bd..75835ab6 100644 --- a/src/js/graph/treeCompare.js +++ b/src/js/graph/treeCompare.js @@ -92,7 +92,7 @@ TreeCompare.compareAllBranchesWithinTrees = function(treeA, treeB) { treeA = this.convertTreeSafe(treeA); treeB = this.convertTreeSafe(treeB); - var allBranches = _.extend( + var allBranches = Object.assign( {}, treeA.branches, treeB.branches @@ -140,7 +140,7 @@ TreeCompare.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) { treeB = this.convertTreeSafe(treeB); this.reduceTreeFields([treeA, treeB]); - var allBranches = _.extend( + var allBranches = Object.assign( {}, treeA.branches, treeB.branches @@ -270,7 +270,7 @@ TreeCompare.getRecurseCompareHashAgnostic = function(treeA, treeB) { // some buildup functions var getStrippedCommitCopy = function(commit) { if (!commit) { return {}; } - return _.extend( + return Object.assign( {}, commit, { diff --git a/src/js/level/builder.js b/src/js/level/builder.js index e823d239..a5a848a6 100644 --- a/src/js/level/builder.js +++ b/src/js/level/builder.js @@ -360,7 +360,7 @@ var LevelBuilder = Level.extend({ }, getExportObj: function() { - var compiledLevel = _.extend( + var compiledLevel = Object.assign( {}, this.level ); diff --git a/src/js/level/index.js b/src/js/level/index.js index 62b6a364..e2801d6e 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -70,7 +70,7 @@ var Level = Sandbox.extend({ // if there is a multiview in the beginning, open that // and let it resolve our deferred if (this.level.startDialog && !this.testOption('noIntroDialog')) { - new MultiView(_.extend( + new MultiView(Object.assign( {}, intl.getStartDialog(this.level), { deferred: deferred } @@ -99,7 +99,7 @@ var Level = Sandbox.extend({ var dialog = $.extend({}, intl.getStartDialog(levelObj)); // grab the last slide only dialog.childViews = dialog.childViews.slice(-1); - new MultiView(_.extend( + new MultiView(Object.assign( dialog, { deferred: deferred } )); diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 6da2b6a6..83a741b0 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -134,7 +134,7 @@ var getAllCommands = function() { 'mobileAlert' ]; - var allCommands = _.extend( + var allCommands = Object.assign( {}, require('../level').regexMap, regexMap diff --git a/src/js/views/builderViews.js b/src/js/views/builderViews.js index bc8cc01d..9d2ba96f 100644 --- a/src/js/views/builderViews.js +++ b/src/js/views/builderViews.js @@ -179,7 +179,7 @@ var DemonstrationBuilder = ContainedBase.extend({ this.deferred = options.deferred || Q.defer(); if (options.fromObj) { var toEdit = options.fromObj.options; - options = _.extend( + options = Object.assign( {}, options, toEdit, diff --git a/src/js/views/gitDemonstrationView.js b/src/js/views/gitDemonstrationView.js index 0c088c26..f0fa0810 100644 --- a/src/js/views/gitDemonstrationView.js +++ b/src/js/views/gitDemonstrationView.js @@ -25,7 +25,7 @@ var GitDemonstrationView = ContainedBase.extend({ initialize: function(options) { options = options || {}; this.options = options; - this.JSON = _.extend( + this.JSON = Object.assign( { beforeMarkdowns: [ '## Git Commits', diff --git a/src/js/views/index.js b/src/js/views/index.js index b98d034a..7182d2a0 100644 --- a/src/js/views/index.js +++ b/src/js/views/index.js @@ -372,7 +372,7 @@ var ConfirmCancelTerminal = Backbone.View.extend({ options = options || {}; this.deferred = options.deferred || Q.defer(); - this.modalAlert = new ModalAlert(_.extend( + this.modalAlert = new ModalAlert(Object.assign( {}, { markdown: '#you sure?' }, options @@ -470,7 +470,7 @@ var NextLevelConfirm = ConfirmCancelTerminal.extend({ '

'; } - options = _.extend( + options = Object.assign( {}, options, { diff --git a/src/js/views/multiView.js b/src/js/views/multiView.js index 79ec192b..faffa3d0 100644 --- a/src/js/views/multiView.js +++ b/src/js/views/multiView.js @@ -159,7 +159,7 @@ var MultiView = Backbone.View.extend({ if (!this.typeToConstructor[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, { wait: true } diff --git a/src/js/visuals/tree.js b/src/js/visuals/tree.js index e5952228..5d9b92dd 100644 --- a/src/js/visuals/tree.js +++ b/src/js/visuals/tree.js @@ -13,7 +13,7 @@ var VisBase = Backbone.Model.extend({ animateAttrKeys: function(keys, attrObj, speed, easing) { // either we animate a specific subset of keys or all // possible things we could animate - keys = _.extend( + keys = Object.assign( {}, { include: ['circle', 'arrow', 'rect', 'path', 'text'], @@ -26,7 +26,7 @@ var VisBase = Backbone.Model.extend({ // safely insert this attribute into all the keys we want _.each(keys.include, function(key) { - attr[key] = _.extend( + attr[key] = Object.assign( {}, attr[key], attrObj diff --git a/src/js/visuals/visBase.js b/src/js/visuals/visBase.js index 92eff1b2..5196a575 100644 --- a/src/js/visuals/visBase.js +++ b/src/js/visuals/visBase.js @@ -58,7 +58,7 @@ var VisBase = Backbone.Model.extend({ animateAttrKeys: function(keys, attrObj, speed, easing) { // either we animate a specific subset of keys or all // possible things we could animate - keys = _.extend( + keys = Object.assign( {}, { include: ['circle', 'arrow', 'rect', 'path', 'text'], @@ -71,7 +71,7 @@ var VisBase = Backbone.Model.extend({ // safely insert this attribute into all the keys we want _.each(keys.include, function(key) { - attr[key] = _.extend( + attr[key] = Object.assign( {}, attr[key], attrObj diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index 3ac6b0f4..5cf27cb4 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -104,7 +104,7 @@ var Visualization = Backbone.View.extend({ makeOrigin: function(options) { // oh god, here we go. We basically do a bizarre form of composition here, // 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... this.options, From 489a4b9095bd96d5ef98746a99f73a56a454f16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 06:37:25 +0700 Subject: [PATCH 02/13] change '_.clone(..args)' to 'Object.assign({}, ..args)' --- src/js/git/index.js | 2 +- src/js/graph/treeCompare.js | 4 ++-- src/js/intl/index.js | 5 +++-- src/js/views/gitDemonstrationView.js | 3 +-- src/js/views/index.js | 8 ++++---- src/js/views/levelDropdownView.js | 3 +-- src/js/views/multiView.js | 3 +-- src/js/visuals/visualization.js | 3 +-- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/js/git/index.js b/src/js/git/index.js index 7754f2ae..2e163168 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -726,7 +726,7 @@ GitEngine.prototype.makeTag = function(id, target) { }; GitEngine.prototype.getHead = function() { - return _.clone(this.HEAD); + return Object.assign({}, this.HEAD); }; GitEngine.prototype.getTags = function() { diff --git a/src/js/graph/treeCompare.js b/src/js/graph/treeCompare.js index 75835ab6..823076b0 100644 --- a/src/js/graph/treeCompare.js +++ b/src/js/graph/treeCompare.js @@ -165,8 +165,8 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran } // don't mess up the rest of comparison - branchA = _.clone(branchA); - branchB = _.clone(branchB); + branchA = Object.assign({}, branchA); + branchB = Object.assign({}, branchB); branchA.target = this.getBaseRef(branchA.target); branchB.target = this.getBaseRef(branchB.target); diff --git a/src/js/intl/index.js b/src/js/intl/index.js index 57fbabed..bab78fe5 100644 --- a/src/js/intl/index.js +++ b/src/js/intl/index.js @@ -11,7 +11,7 @@ var fallbackMap = { // lets change underscores template settings so it interpolates // things like "{branchName} does not exist". -var templateSettings = _.clone(_.templateSettings); +var templateSettings = Object.assign({}, _.templateSettings); templateSettings.interpolate = /\{(.+?)\}/g; var template = exports.template = function(str, params) { return _.template(str, params, templateSettings); @@ -106,7 +106,8 @@ exports.getStartDialog = function(level) { markdown: str('error-untranslated') } }; - var startCopy = _.clone( + var startCopy = Object.assign( + {}, level.startDialog[getDefaultLocale()] || level.startDialog ); startCopy.childViews.unshift(errorAlert); diff --git a/src/js/views/gitDemonstrationView.js b/src/js/views/gitDemonstrationView.js index f0fa0810..e769bd78 100644 --- a/src/js/views/gitDemonstrationView.js +++ b/src/js/views/gitDemonstrationView.js @@ -55,7 +55,7 @@ var GitDemonstrationView = ContainedBase.extend({ this.render(); this.checkScroll(); - this.navEvents = _.clone(Backbone.Events); + this.navEvents = Object.assign({}, Backbone.Events); this.navEvents.on('positive', this.positive, this); this.navEvents.on('negative', this.negative, this); this.keyboardListener = new KeyboardListener({ @@ -244,4 +244,3 @@ var GitDemonstrationView = ContainedBase.extend({ }); exports.GitDemonstrationView = GitDemonstrationView; - diff --git a/src/js/views/index.js b/src/js/views/index.js index 7182d2a0..6f09413b 100644 --- a/src/js/views/index.js +++ b/src/js/views/index.js @@ -86,7 +86,7 @@ var GeneralButton = ContainedBase.extend({ initialize: function(options) { options = options || {}; - this.navEvents = options.navEvents || _.clone(Backbone.Events); + this.navEvents = options.navEvents || Object.assign({}, Backbone.Events); this.destination = options.destination; if (!this.destination) { 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 // click events this.pipeEvents = options.events; - this.navEvents = _.clone(Backbone.Events); + this.navEvents = Object.assign({}, Backbone.Events); this.JSON = { showLeft: (options.showLeft === undefined) ? true : options.showLeft, @@ -305,7 +305,7 @@ var ModalTerminal = ContainedBase.extend({ initialize: function(options) { options = options || {}; - this.navEvents = options.events || _.clone(Backbone.Events); + this.navEvents = options.events || Object.assign({}, Backbone.Events); this.container = new ModalView(); this.JSON = { @@ -395,7 +395,7 @@ var ConfirmCancelTerminal = Backbone.View.extend({ }.bind(this)); // also setup keyboard - this.navEvents = _.clone(Backbone.Events); + this.navEvents = Object.assign({}, Backbone.Events); this.navEvents.on('positive', this.positive, this); this.navEvents.on('negative', this.negative, this); this.keyboardListener = new KeyboardListener({ diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 79858ed0..31c29024 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -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.loadLevelID.bind(this), 300, @@ -444,4 +444,3 @@ var SeriesView = BaseView.extend({ }); exports.LevelDropdownView = LevelDropdownView; - diff --git a/src/js/views/multiView.js b/src/js/views/multiView.js index faffa3d0..d85bafb9 100644 --- a/src/js/views/multiView.js +++ b/src/js/views/multiView.js @@ -48,7 +48,7 @@ var MultiView = Backbone.View.extend({ this.childViews = []; this.currentIndex = 0; - this.navEvents = _.clone(Backbone.Events); + this.navEvents = Object.assign({}, Backbone.Events); this.navEvents.on('negative', this.getNegFunc(), this); this.navEvents.on('positive', this.getPosFunc(), this); this.navEvents.on('quit', this.finish, this); @@ -192,4 +192,3 @@ var MultiView = Backbone.View.extend({ }); exports.MultiView = MultiView; - diff --git a/src/js/visuals/visualization.js b/src/js/visuals/visualization.js index 5cf27cb4..739af574 100644 --- a/src/js/visuals/visualization.js +++ b/src/js/visuals/visualization.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Collections = require('../models/collections'); @@ -13,7 +12,7 @@ var Visualization = Backbone.View.extend({ initialize: function(options) { options = options || {}; this.options = options; - this.customEvents = _.clone(Backbone.Events); + this.customEvents = Object.assign({}, Backbone.Events); this.containerElement = options.containerElement; var _this = this; From 0134bf9870546b30dbedab4ccff114fd0e94897b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:05:27 +0700 Subject: [PATCH 03/13] Replace some '_.each' with 'Array.prototype.forEach' --- Gruntfile.js | 5 +-- src/js/commands/index.js | 4 +- src/js/git/commands.js | 3 +- src/js/git/index.js | 94 +++++++++++++++++++--------------------- 4 files changed, 50 insertions(+), 56 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 4d007c18..ab271d4a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -62,7 +62,7 @@ module.exports = function(grunt) { hashedMinFile = 'bundle.js'; } var jsRegex = /bundle\.min\.\w+\.js/; - _.each(buildFiles, function(jsFile) { + buildFiles.forEach(function(jsFile) { if (jsRegex.test(jsFile)) { if (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 hashedStyleFile; - _.each(buildFiles, function(styleFile) { + buildFiles.forEach(function(styleFile) { if (styleRegex.test(styleFile)) { if (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('casperTest', ['shell:casperTest']); }; - diff --git a/src/js/commands/index.js b/src/js/commands/index.js index 2f896e1c..64706d34 100644 --- a/src/js/commands/index.js +++ b/src/js/commands/index.js @@ -34,7 +34,7 @@ var commands = { if (result.multiDelegate) { // we need to do multiple delegations with // a different command at each step - _.each(result.multiDelegate, function(delConfig) { + result.multiDelegate.forEach(function(delConfig) { // copy command, and then set opts commandObj.setOptionsMap(delConfig.options || {}); commandObj.setGeneralArgs(delConfig.args || []); @@ -70,7 +70,7 @@ var commands = { var displayName = config.displayName || name; var thisMap = {}; // start all options off as disabled - _.each(config.options, function(option) { + (config.options || []).forEach(function(option) { thisMap[option] = false; }); optionMap[vcs][displayName] = thisMap; diff --git a/src/js/git/commands.js b/src/js/git/commands.js index cdec783b..949f47ae 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -431,7 +431,7 @@ var commandConfig = { names = names.concat(generalArgs); command.validateArgBounds(names, 1, Number.MAX_VALUE, '-d'); - _.each(names, function(name) { + names.forEach(function(name) { engine.validateAndDeleteBranch(name); }); return; @@ -856,4 +856,3 @@ var instantCommands = [ exports.commandConfig = commandConfig; exports.instantCommands = instantCommands; - diff --git a/src/js/git/index.js b/src/js/git/index.js index 2e163168..e38fe572 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -170,7 +170,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) { // now loop through and delete commits var commitsToLoop = tree.commits; tree.commits = {}; - _.each(commitsToLoop, function(commit, id) { + commitsToLoop.forEach(function(commit, id) { if (set[id]) { // if included in target branch tree.commits[id] = commit; @@ -179,7 +179,7 @@ GitEngine.prototype.exportTreeForBranch = function(branchName) { var branchesToLoop = tree.branches; tree.branches = {}; - _.each(branchesToLoop, function(branch, id) { + branchesToLoop.forEach(function(branch, id) { if (id === branchName) { tree.branches[id] = branch; } @@ -200,30 +200,28 @@ GitEngine.prototype.exportTree = function() { HEAD: null }; - _.each(this.branchCollection.toJSON(), function(branch) { + this.branchCollection.toJSON().forEach(function(branch) { branch.target = branch.target.get('id'); delete branch.visBranch; 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 - _.each(Commit.prototype.constants.circularFields, function(field) { + Commit.prototype.constants.circularFields.forEach(function(field) { delete commit[field]; - }, this); + }); // convert parents - var parents = []; - _.each(commit.parents, function(par) { - parents.push(par.get('id')); + commit.parents = (commit.parents || []).map(function(par) { + return par.get('id'); }); - commit.parents = parents; totalExport.commits[commit.id] = commit; }, this); - _.each(this.tagCollection.toJSON(), function(tag) { + this.tagCollection.toJSON().forEach(function(tag) { delete tag.visTag; tag.target = tag.target.get('id'); @@ -558,9 +556,8 @@ GitEngine.prototype.getOrMakeRecursive = function( // for commits, we need to grab all the parents var commitJSON = tree.commits[objID]; - var parentObjs = []; - _.each(commitJSON.parents, function(parentID) { - parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); + var parentObjs = commitJSON.parents.map(function(parentID) { + return this.getOrMakeRecursive(tree, createdSoFar, parentID); }, this); var commit = new Commit(Object.assign( @@ -774,17 +771,16 @@ GitEngine.prototype.printBranchesWithout = function(without) { var commitToBranches = this.getUpstreamBranchSet(); var commitID = this.getCommitFromRef(without).get('id'); - var toPrint = []; - _.each(commitToBranches[commitID], function(branchJSON) { + var toPrint = commitToBranches[commitID].map(function (branchJSON) { branchJSON.selected = this.HEAD.get('target').get('id') == branchJSON.id; - toPrint.push(branchJSON); + return branchJSON; }, this); this.printBranches(toPrint); }; GitEngine.prototype.printBranches = function(branches) { var result = ''; - _.each(branches, function(branch) { + branches.forEach(function (branch) { result += (branch.selected ? '* ' : '') + branch.id + '\n'; }); throw new CommandResult({ @@ -794,7 +790,7 @@ GitEngine.prototype.printBranches = function(branches) { GitEngine.prototype.printTags = function(tags) { var result = ''; - _.each(tags, function(tag) { + tags.forEach(function (tag) { result += tag.id + '\n'; }); throw new CommandResult({ @@ -895,11 +891,11 @@ GitEngine.prototype.revert = function(whichCommits) { }.bind(this); // set up the promise chain - _.each(toRevert, function(commit) { + toRevert.forEach(function (commit) { chain = chain.then(function() { return chainStep(commit); }); - }, this); + }); // done! update our location chain = chain.then(function() { @@ -934,7 +930,7 @@ GitEngine.prototype.setupCherrypickChain = function(toCherrypick) { ); }.bind(this); - _.each(toCherrypick, function(arg) { + toCherrypick.forEach(function (arg) { chain = chain.then(function() { return chainStep(arg); }); @@ -1015,7 +1011,7 @@ GitEngine.prototype.getTargetGraphDifference = function( while (toExplore.length) { var here = toExplore.pop(); difference.push(here); - _.each(here.parents, pushParent); + here.parents.forEach(pushParent); } // filter because we weren't doing graph search @@ -1160,7 +1156,7 @@ GitEngine.prototype.push = function(options) { var deferred = Q.defer(); var chain = deferred.promise; - _.each(commitsToMake, function(commitJSON) { + commitsToMake.forEach(function(commitJSON) { chain = chain.then(function() { return this.animationFactory.playHighlightPromiseAnimation( 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. // this check essentially pretends the local remote branch is in origin and // could be fast forwarded (basic sanity check) - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { this.checkUpstreamOfSource( this, this.origin, @@ -1278,7 +1274,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { // then we get the difference in commits between these two graphs var commitsToMake = []; - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { commitsToMake = commitsToMake.concat(this.getTargetGraphDifference( this, this.origin, @@ -1341,7 +1337,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { } var originBranchSet = this.origin.getUpstreamBranchSet(); - _.each(commitsToMake, function(commitJSON) { + commitsToMake.forEach(function (commitJSON) { // technically we could grab the wrong one here // but this works for now var originBranch = originBranchSet[commitJSON.id][0].obj; @@ -1364,7 +1360,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { chain = chain.then(function() { // update all the destinations - _.each(sourceDestPairs, function(pair) { + sourceDestPairs.forEach(function (pair) { var ours = this.refs[pair.destination]; var theirCommitID = this.origin.getCommitFromRef(pair.source).get('id'); // by definition we just made the commit with this id, @@ -1736,8 +1732,8 @@ GitEngine.prototype.updateBranchesFromSet = function(commitSet) { var branchesToUpdate = {}; // now loop over the set we got passed in and find which branches // that means (aka intersection) - _.each(commitSet, function(val, id) { - _.each(upstreamSet[id], function(branchJSON) { + commitSet.forEach(function (val, id) { + upstreamSet[id].forEach(function (branchJSON) { branchesToUpdate[branchJSON.id] = true; }); }, this); @@ -1777,7 +1773,7 @@ GitEngine.prototype.syncRemoteBranchFills = function() { GitEngine.prototype.updateBranchesForHg = function(branchList) { var hasUpdated = false; - _.each(branchList, function(branchID) { + branchList.forEach(function (branchID) { // ok now just check if this branch has a more recent commit available. // that mapping is easy because we always do rebase alt id -- // 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')); } - _.each(toDelete, function(commit) { + toDelete.forEach(function (commit) { commit.removeFromParents(); this.commitCollection.remove(commit); @@ -1877,7 +1873,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) { var inArray = function(arr, id) { var found = false; - _.each(arr, function(wrapper) { + arr.forEach(function (wrapper) { if (wrapper.id == id) { found = true; } @@ -1902,7 +1898,7 @@ GitEngine.prototype.getUpstreamCollectionSet = function(collection) { collection.each(function(ref) { var set = bfsSearch(ref.get('target')); - _.each(set, function(id) { + set.forEach(function (id) { commitToSet[id] = commitToSet[id] || []; // 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) { var set = {}; - _.each(this.getUpstreamDiffFromSet(stopSet, location), function(commit) { + this.getUpstreamDiffFromSet(stopSet, location).forEach(function (commit) { set[commit.get('id')] = true; }); 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 var toRebase = []; - _.each(toRebaseRough, function(commit) { + toRebaseRough.forEach(function (commit) { if (commit.get('parents').length == 1) { toRebase.push(commit); } @@ -2211,7 +2207,7 @@ GitEngine.prototype.rebaseInteractiveTest = function(targetSource, currentLocati var toRebase = this.getInteractiveRebaseCommits(targetSource, currentLocation); var rebaseMap = {}; - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { var id = commit.get('id'); 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 var extraCommits = []; rebaseOrder = []; - _.each(idsToRebase, function(id) { + idsToRebase.forEach(function (id) { if (id in rebaseMap) { rebaseOrder.push(rebaseMap[id]); } else { @@ -2281,13 +2277,13 @@ GitEngine.prototype.rebaseInteractive = function(targetSource, currentLocation, var initialCommitOrdering; if (options.initialCommitOrdering && options.initialCommitOrdering.length > 0) { var rebaseMap = {}; - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { rebaseMap[commit.get('id')] = true; }); // Verify each chosen commit exists in the list of commits given to the user initialCommitOrdering = []; - _.each(options.initialCommitOrdering[0].split(','), function(id) { + options.initialCommitOrdering[0].split(',').forEach(function (id) { if (!rebaseMap[id]) { throw new GitError({ msg: intl.todo('Hey those commits don\'t exist in the set!') @@ -2406,7 +2402,7 @@ GitEngine.prototype.rebaseFinish = function( }.bind(this); // set up the promise chain - _.each(toRebase, function(commit) { + toRebase.forEach(function (commit) { chain = chain.then(function() { 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 // first we need to get a reverse mapping from tag to commit var tagMap = {}; - _.each(this.tagCollection.toJSON(), function(tag) { + this.tagCollection.toJSON().forEach(function (tag) { tagMap[tag.target.get('id')] = tag.id; }); @@ -2733,7 +2729,7 @@ GitEngine.prototype.status = function() { lines.push(intl.str('git-status-readytocommit')); var msg = ''; - _.each(lines, function(line) { + lines.forEach(function (line) { msg += '# ' + line + '\n'; }); @@ -2776,7 +2772,7 @@ GitEngine.prototype.log = function(ref, omitSet) { // now go through and collect logs var bigLogStr = ''; - _.each(toDump, function(c) { + toDump.forEach(function (c) { bigLogStr += c.getLogEntry(); }, this); @@ -2831,7 +2827,7 @@ GitEngine.prototype.getDownstreamSet = function(ancestor) { var here = queue.pop(); var children = here.get('children'); - _.each(children, addToExplored); + children.forEach(addToExplored); } return exploredSet; }; @@ -3009,7 +3005,7 @@ var Commit = Backbone.Model.extend({ }, removeFromParents: function() { - _.each(this.get('parents'), function(parent) { + this.get('parents').forEach(function (parent) { parent.removeChild(this); }, this); }, @@ -3052,11 +3048,11 @@ var Commit = Backbone.Model.extend({ removeChild: function(childToRemove) { var newChildren = []; - _.each(this.get('children'), function(child) { + this.get('children').forEach(function (child) { if (child !== childToRemove) { newChildren.push(child); } - }, this); + }); this.set('children', newChildren); }, @@ -3069,7 +3065,7 @@ var Commit = Backbone.Model.extend({ this.validateAtInit(); this.addNodeToVisuals(); - _.each(this.get('parents'), function(parent) { + (this.get('parents') || []).forEach(function (parent) { parent.get('children').push(this); this.addEdgeToVisuals(parent); }, this); From 7af2db3da50391d12e7a6f00cb55ccf61306b270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:20:42 +0700 Subject: [PATCH 04/13] Replace '_.map' to 'Array.prototype.map' --- src/js/git/commands.js | 2 +- src/js/git/index.js | 12 ++++++------ src/js/models/commandModel.js | 2 +- src/js/views/gitDemonstrationView.js | 4 ++-- src/js/views/levelDropdownView.js | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 949f47ae..0b8528eb 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -190,7 +190,7 @@ var commandConfig = { var set = Graph.getUpstreamSet(engine, 'HEAD'); // 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); // and check that its not upstream if (set[commit.get('id')]) { diff --git a/src/js/git/index.js b/src/js/git/index.js index e38fe572..b6874e8f 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -857,7 +857,7 @@ GitEngine.prototype.makeCommit = function(parents, id, options) { GitEngine.prototype.revert = function(whichCommits) { // resolve the commits we will rebase - var toRevert = _.map(whichCommits, function(stringRef) { + var toRevert = whichCommits.map(function(stringRef) { return this.getCommitFromRef(stringRef); }, this); @@ -1138,7 +1138,7 @@ GitEngine.prototype.push = function(options) { var makeCommit = function(id, parentIDs) { // need to get the parents first. since we order by depth, we know // the dependencies are there already - var parents = _.map(parentIDs, function(parentID) { + var parents = parentIDs.map(function(parentID) { return this.origin.refs[parentID]; }, this); return this.origin.makeCommit(parents, id); @@ -1246,7 +1246,7 @@ GitEngine.prototype.fetch = function(options) { } // get all remote branches and specify the dest / source pairs var allBranchesOnRemote = this.origin.branchCollection.toArray(); - var sourceDestPairs = _.map(allBranchesOnRemote, function(branch) { + var sourceDestPairs = allBranchesOnRemote.map(function(branch) { var branchName = branch.get('id'); didMakeBranch = didMakeBranch || this.makeRemoteBranchIfNeeded(branchName); @@ -1312,7 +1312,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { var makeCommit = function(id, parentIDs) { // need to get the parents first. since we order by depth, we know // the dependencies are there already - var parents = _.map(parentIDs, function(parentID) { + var parents = parentIDs.map(function(parentID) { return this.refs[parentID]; }, this); return this.makeCommit(parents, id); @@ -1738,7 +1738,7 @@ GitEngine.prototype.updateBranchesFromSet = function(commitSet) { }); }, this); - var branchList = _.map(branchesToUpdate, function(val, id) { + var branchList = branchesToUpdate.map(function(val, id) { return id; }); return this.updateBranchesForHg(branchList); @@ -2340,7 +2340,7 @@ GitEngine.prototype.filterRebaseCommits = function( GitEngine.prototype.getRebasePreserveMergesParents = function(oldCommit) { var oldParents = oldCommit.get('parents'); - return _.map(oldParents, function(parent) { + return oldParents.map(function(parent) { var oldID = parent.get('id'); var newID = this.getMostRecentBumpedID(oldID); return this.refs[newID]; diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index a8264ba6..f8932e10 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -78,7 +78,7 @@ var Command = Backbone.Model.extend({ var generalArgs = this.getGeneralArgs(); var options = this.getOptionsMap(); - generalArgs = _.map(generalArgs, function(arg) { + generalArgs = generalArgs.map(function(arg) { return this.replaceDotWithHead(arg); }, this); var newMap = {}; diff --git a/src/js/views/gitDemonstrationView.js b/src/js/views/gitDemonstrationView.js index e769bd78..96460200 100644 --- a/src/js/views/gitDemonstrationView.js +++ b/src/js/views/gitDemonstrationView.js @@ -83,8 +83,8 @@ var GitDemonstrationView = ContainedBase.extend({ }, checkScroll: function() { - var children = this.$('div.demonstrationText').children(); - var heights = _.map(children, function(child) { return child.clientHeight; }); + var children = this.$('div.demonstrationText').children().toArray(); + var heights = children.map(function(child) { return child.clientHeight; }); var totalHeight = _.reduce(heights, function(a, b) { return a + b; }); if (totalHeight < this.$('div.demonstrationText').height()) { this.$('div.demonstrationText').addClass('noLongText'); diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 31c29024..74fd809f 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -211,7 +211,7 @@ var LevelDropdownView = ContainedBase.extend({ }, getTabIndex: function() { - var ids = _.map(this.JSON.tabs, function(tab) { + var ids = this.JSON.tabs.map(function(tab) { return tab.id; }); return ids.indexOf(this.JSON.selectedTab); From e324e51587263c88fdaf0bbfd38f1735ef11d455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:22:40 +0700 Subject: [PATCH 05/13] Replace '_.reduce' to 'Array.prototype.reduce' --- src/js/views/gitDemonstrationView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/views/gitDemonstrationView.js b/src/js/views/gitDemonstrationView.js index 96460200..13b0469f 100644 --- a/src/js/views/gitDemonstrationView.js +++ b/src/js/views/gitDemonstrationView.js @@ -85,7 +85,7 @@ var GitDemonstrationView = ContainedBase.extend({ checkScroll: function() { var children = this.$('div.demonstrationText').children().toArray(); 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()) { this.$('div.demonstrationText').addClass('noLongText'); } From dddf063146890ef4e0a898cd00426fd61f82e62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:27:01 +0700 Subject: [PATCH 06/13] Replace '_.filter' to 'Array.prototype.filter' --- src/js/git/index.js | 10 +++++----- src/js/views/levelDropdownView.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/js/git/index.js b/src/js/git/index.js index b6874e8f..1b3299fc 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -755,14 +755,14 @@ GitEngine.prototype.getBranches = function() { GitEngine.prototype.getRemoteBranches = function() { var all = this.getBranches(); - return _.filter(all, function(branchJSON) { + return all.filter(function(branchJSON) { return branchJSON.remote === true; }); }; GitEngine.prototype.getLocalBranches = function() { var all = this.getBranches(); - return _.filter(all, function(branchJSON) { + return all.filter(function(branchJSON) { return branchJSON.remote === false; }); }; @@ -1131,7 +1131,7 @@ GitEngine.prototype.push = function(options) { // 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 // make them, so filter these out - commitsToMake = _.filter(commitsToMake, function(commitJSON) { + commitsToMake = commitsToMake.filter(function(commitJSON) { return !this.origin.refs[commitJSON.id]; }, this); @@ -1305,7 +1305,7 @@ GitEngine.prototype.fetchCore = function(sourceDestPairs, options) { // 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 // make them, so filter these out - commitsToMake = _.filter(commitsToMake, function(commitJSON) { + commitsToMake = commitsToMake.filter(function(commitJSON) { return !this.refs[commitJSON.id]; }, this); @@ -2315,7 +2315,7 @@ GitEngine.prototype.filterRebaseCommits = function( var uniqueIDs = {}; // resolve the commits we will rebase - return _.filter(toRebaseRough, function(commit) { + return toRebaseRough.filter(function(commit) { // no merge commits, unless we preserve if (commit.get('parents').length !== 1 && !options.preserveMerges) { return false; diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index 74fd809f..cfbfec3d 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -235,7 +235,7 @@ var LevelDropdownView = ContainedBase.extend({ }, getSequencesOnTab: function() { - return _.filter(this.sequences, function(sequenceName) { + return this.sequences.filter(function(sequenceName) { var tab = LEVELS.getTabForSequence(sequenceName); return tab === this.JSON.selectedTab; }, this); From ce61c97cf0e0309fbed2cccfcdb7545cad76a2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:29:11 +0700 Subject: [PATCH 07/13] Replace '_.keys' to 'Object.prototype.keys' --- src/js/stores/LevelStore.js | 2 +- src/js/views/builderViews.js | 3 +-- src/js/views/rebaseView.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/stores/LevelStore.js b/src/js/stores/LevelStore.js index edacc524..3b160c3e 100644 --- a/src/js/stores/LevelStore.js +++ b/src/js/stores/LevelStore.js @@ -89,7 +89,7 @@ AppConstants.StoreSubscribePrototype, }, getSequences: function() { - return _.keys(levelSequences); + return Object.keys(levelSequences); }, getLevelsInSequence: function(sequenceName) { diff --git a/src/js/views/builderViews.js b/src/js/views/builderViews.js index 9d2ba96f..89a6f8b9 100644 --- a/src/js/views/builderViews.js +++ b/src/js/views/builderViews.js @@ -295,7 +295,7 @@ var MultiViewBuilder = ContainedBase.extend({ this.JSON = { views: this.getChildViews(), - supportedViews: _.keys(this.typeToConstructor) + supportedViews: Object.keys(this.typeToConstructor) }; this.container = new ModalTerminal({ @@ -416,4 +416,3 @@ exports.DemonstrationBuilder = DemonstrationBuilder; exports.TextGrabber = TextGrabber; exports.MultiViewBuilder = MultiViewBuilder; exports.MarkdownPresenter = MarkdownPresenter; - diff --git a/src/js/views/rebaseView.js b/src/js/views/rebaseView.js index 49403561..accae218 100644 --- a/src/js/views/rebaseView.js +++ b/src/js/views/rebaseView.js @@ -78,7 +78,7 @@ var InteractiveRebaseView = ContainedBase.extend({ render: function() { var json = { - num: _.keys(this.rebaseMap).length, + num: Object.keys(this.rebaseMap).length, solutionOrder: this.options.initialCommitOrdering }; From e17d974b55984e87c0cba5b24267d612f5db8d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:40:56 +0700 Subject: [PATCH 08/13] Use 'util/escapeString' instead of _.escape --- src/js/git/commands.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 0b8528eb..88bf2bb5 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -1,3 +1,4 @@ +var escapeString = require('../util/escapeString'); var _ = require('underscore'); var intl = require('../intl'); @@ -830,7 +831,7 @@ var instantCommands = [ intl.str('git-version'), '
', intl.str('git-usage'), - _.escape(intl.str('git-usage-command')), + escapeString(intl.str('git-usage-command')), '
', intl.str('git-supported-commands'), '
' From d87fd095c083033d2cce7467ec5900318f4d6f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 08:51:03 +0700 Subject: [PATCH 09/13] Use 'Object.values' and 'Object.keys' to get list 'keys' and 'values' --- src/js/git/index.js | 4 +--- src/js/models/commandModel.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/js/git/index.js b/src/js/git/index.js index 1b3299fc..d92567d7 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -2090,9 +2090,7 @@ GitEngine.prototype.hgRebase = function(destination, base) { }); }); - var branchList = _.map(branchMap, function(val, id) { - return id; - }); + var branchList = Object.keys(branchMap); chain = chain.then(function() { // now we just moved a bunch of commits, but we haven't updated the diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index f8932e10..07f02c87 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -83,7 +83,7 @@ var Command = Backbone.Model.extend({ }, this); var newMap = {}; _.each(options, function(args, key) { - newMap[key] = _.map(args, function(arg) { + newMap[key] = Object.values(args).map(function (arg) { return this.replaceDotWithHead(arg); }, this); }, this); From bd8009386de0cb04763619cb1bb45e036be8c1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 11:28:04 +0700 Subject: [PATCH 10/13] Use 'Array.prototype.forEach' instead of '_.each' and '_.forEach' --- src/js/git/index.js | 12 +++++------- src/js/graph/index.js | 6 +++--- src/js/graph/treeCompare.js | 16 ++++++++-------- src/js/level/parseWaterfall.js | 9 ++++----- src/js/models/commandModel.js | 2 +- src/js/sandbox/commands.js | 4 ++-- src/js/stores/LevelStore.js | 4 ++-- src/js/views/commandViews.js | 3 +-- src/js/views/gitDemonstrationView.js | 2 +- src/js/views/levelDropdownView.js | 8 ++++---- src/js/views/multiView.js | 4 ++-- src/js/views/rebaseView.js | 4 ++-- src/js/visuals/index.js | 26 +++++++++++++------------- src/js/visuals/tree.js | 7 +++---- src/js/visuals/visBase.js | 11 +++++------ src/js/visuals/visBranch.js | 11 +++++------ src/js/visuals/visEdge.js | 2 +- src/js/visuals/visNode.js | 16 ++++++++-------- src/js/visuals/visTag.js | 9 ++++----- 19 files changed, 74 insertions(+), 82 deletions(-) diff --git a/src/js/git/index.js b/src/js/git/index.js index d92567d7..abbf4408 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -1551,11 +1551,9 @@ GitEngine.prototype.fakeTeamwork = function(numToMake, branch) { var deferred = Q.defer(); var chain = deferred.promise; - _.each(_.range(numToMake), function(i) { - chain = chain.then(function() { - return chainStep(); - }); - }); + for(var i = 0; i < numToMake; i++) { + chain = chain.then(chainStep); + } this.animationQueue.thenFinish(chain, deferred); }; @@ -2074,7 +2072,7 @@ GitEngine.prototype.hgRebase = function(destination, base) { var masterSet = {}; masterSet[baseCommit.get('id')] = true; - _.each([upstream, downstream].concat(moreSets), function(set) { + [upstream, downstream].concat(moreSets).forEach(function(set) { _.each(set, function(val, id) { masterSet[id] = true; }); @@ -2085,7 +2083,7 @@ GitEngine.prototype.hgRebase = function(destination, base) { var upstreamSet = this.getUpstreamBranchSet(); _.each(masterSet, function(val, commitID) { // now loop over that commits branches - _.each(upstreamSet[commitID], function(branchJSON) { + upstreamSet[commitID].forEach(function(branchJSON) { branchMap[branchJSON.id] = true; }); }); diff --git a/src/js/graph/index.js b/src/js/graph/index.js index ed2c0745..584f788d 100644 --- a/src/js/graph/index.js +++ b/src/js/graph/index.js @@ -85,7 +85,7 @@ var Graph = { var commitJSON = tree.commits[objID]; var parentObjs = []; - _.each(commitJSON.parents, function(parentID) { + commitJSON.parents.forEach(function(parentID) { parentObjs.push(this.getOrMakeRecursive(tree, createdSoFar, parentID)); }, this); @@ -143,7 +143,7 @@ var Graph = { var here = queue.pop(); var rents = here.get('parents'); - _.each(rents, addToExplored); + (rents || []).forEach(addToExplored); } return exploredSet; }, @@ -151,7 +151,7 @@ var Graph = { getUniqueObjects: function(objects) { var unique = {}; var result = []; - _.forEach(objects, function(object) { + objects.forEach(function(object) { if (unique[object.id]) { return; } diff --git a/src/js/graph/treeCompare.js b/src/js/graph/treeCompare.js index 823076b0..6318a3ec 100644 --- a/src/js/graph/treeCompare.js +++ b/src/js/graph/treeCompare.js @@ -115,7 +115,7 @@ TreeCompare.compareAllTagsWithinTrees = function(treeA, treeB) { TreeCompare.compareBranchesWithinTrees = function(treeA, treeB, branches) { var result = true; - _.each(branches, function(branchName) { + branches.forEach(function(branchName) { result = result && this.compareBranchWithinTrees(treeA, treeB, branchName); }, this); @@ -176,7 +176,7 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran var recurseCompare = this.getRecurseCompareHashAgnostic(treeA, treeB); var result = true; - _.each(branches, function(branchName) { + branches.forEach(function(branchName) { var branchA = treeA.branches[branchName]; var branchB = treeB.branches[branchName]; @@ -217,7 +217,7 @@ TreeCompare.evalAssertsOnBranch = function(tree, branchName, asserts) { } var result = true; - _.each(asserts, function(assert) { + asserts.forEach(function(assert) { try { result = result && assert(data); } catch (err) { @@ -305,7 +305,7 @@ TreeCompare.getRecurseCompare = function(treeA, treeB, options) { // so the index lookup is valid. for merge commits this will duplicate some of the // checking (because we aren't doing graph search) but it's not a huge deal var maxNumParents = Math.max(commitA.parents.length, commitB.parents.length); - _.each(_.range(maxNumParents), function(index) { + for (var index = 0; index < maxNumParents; index++) { var pAid = commitA.parents[index]; var pBid = commitB.parents[index]; @@ -315,7 +315,7 @@ TreeCompare.getRecurseCompare = function(treeA, treeB, options) { var childB = treeB.commits[pBid]; result = result && recurseCompare(childA, childB); - }, this); + } // if each of our children recursively are equal, we are good return result; }; @@ -377,7 +377,7 @@ TreeCompare.reduceTreeFields = function(trees) { tags: {} }; - _.each(trees, function(tree) { + trees.forEach(function(tree) { _.each(treeDefaults, function(val, key) { if (tree[key] === undefined) { tree[key] = val; @@ -391,7 +391,7 @@ TreeCompare.reduceTreeFields = function(trees) { _.each(objects, function(obj, objKey) { // our blank slate to copy over var blank = {}; - _.each(saveFields, function(field) { + saveFields.forEach(function(field) { if (obj[field] !== undefined) { blank[field] = obj[field]; } else if (defaults[field] !== undefined) { @@ -410,7 +410,7 @@ TreeCompare.reduceTreeFields = function(trees) { }); }; - _.each(trees, function(tree) { + trees.forEach(function(tree) { saveOnly(tree, 'commits', commitSaveFields, commitSortFields); saveOnly(tree, 'branches', branchSaveFields); saveOnly(tree, 'tags', tagSaveFields); diff --git a/src/js/level/parseWaterfall.js b/src/js/level/parseWaterfall.js index 4a711f4f..d84fde97 100644 --- a/src/js/level/parseWaterfall.js +++ b/src/js/level/parseWaterfall.js @@ -68,7 +68,7 @@ ParseWaterfall.prototype.addLast = function(which, value) { }; ParseWaterfall.prototype.expandAllShortcuts = function(commandStr) { - _.each(this.shortcutWaterfall, function(shortcutMap) { + this.shortcutWaterfall.forEach(function(shortcutMap) { commandStr = this.expandShortcut(commandStr, shortcutMap); }, this); return commandStr; @@ -87,13 +87,13 @@ ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) { }; ParseWaterfall.prototype.processAllInstants = function(commandStr) { - _.each(this.instantWaterfall, function(instantCommands) { + this.instantWaterfall.forEach(function(instantCommands) { this.processInstant(commandStr, instantCommands); }, this); }; ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands) { - _.each(instantCommands, function(tuple) { + instantCommands.forEach(function(tuple) { var regex = tuple[0]; var results = regex.exec(commandStr); if (results) { @@ -109,7 +109,7 @@ ParseWaterfall.prototype.parseAll = function(commandStr) { } var toReturn = false; - _.each(this.parseWaterfall, function(parseFunc) { + this.parseWaterfall.forEach(function(parseFunc) { var results = parseFunc(commandStr); if (results) { toReturn = results; @@ -120,4 +120,3 @@ ParseWaterfall.prototype.parseAll = function(commandStr) { }; exports.ParseWaterfall = ParseWaterfall; - diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index 07f02c87..b8a9569f 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -93,7 +93,7 @@ var Command = Backbone.Model.extend({ deleteOptions: function(options) { var map = this.getOptionsMap(); - _.each(options, function(option) { + options.forEach(function(option) { delete map[option]; }, this); this.setOptionsMap(map); diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 83a741b0..8e3f57b1 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -98,7 +98,7 @@ var instantCommands = [ intl.str('show-all-commands'), '
' ]; - _.each(allCommands, function(regex, command) { + allCommands.forEach(function(regex, command) { lines.push(command); }); @@ -144,7 +144,7 @@ var getAllCommands = function() { allCommands[vcs + ' ' + method] = regex; }); }); - _.each(toDelete, function(key) { + toDelete.forEach(function(key) { delete allCommands[key]; }); diff --git a/src/js/stores/LevelStore.js b/src/js/stores/LevelStore.js index 3b160c3e..9f951b06 100644 --- a/src/js/stores/LevelStore.js +++ b/src/js/stores/LevelStore.js @@ -41,7 +41,7 @@ var validateLevel = function(level) { 'solutionCommand' ]; - _.each(requiredFields, function(field) { + requiredFields.forEach(function(field) { if (level[field] === undefined) { console.log(level); throw new Error('I need this field for a level: ' + field); @@ -59,7 +59,7 @@ _.each(levelSequences, function(levels, levelSequenceName) { } // for this particular sequence... - _.each(levels, function(level, index) { + levels.forEach(function(level, index) { validateLevel(level); var id = levelSequenceName + String(index + 1); diff --git a/src/js/views/commandViews.js b/src/js/views/commandViews.js index 63ebef01..8dfa71ef 100644 --- a/src/js/views/commandViews.js +++ b/src/js/views/commandViews.js @@ -173,7 +173,7 @@ var CommandPromptView = Backbone.View.extend({ which.reverse(); var str = ''; - _.each(which, function(text) { + which.forEach(function(text) { str += text + ';'; }, this); @@ -202,4 +202,3 @@ var CommandPromptView = Backbone.View.extend({ }); exports.CommandPromptView = CommandPromptView; - diff --git a/src/js/views/gitDemonstrationView.js b/src/js/views/gitDemonstrationView.js index 13b0469f..fc1da36d 100644 --- a/src/js/views/gitDemonstrationView.js +++ b/src/js/views/gitDemonstrationView.js @@ -168,7 +168,7 @@ var GitDemonstrationView = ContainedBase.extend({ var chainDeferred = Q.defer(); var chainPromise = chainDeferred.promise; - _.each(commands, function(command, index) { + commands.forEach(function(command, index) { chainPromise = chainPromise.then(function() { var myDefer = Q.defer(); this.mainVis.gitEngine.dispatch(command, myDefer); diff --git a/src/js/views/levelDropdownView.js b/src/js/views/levelDropdownView.js index cfbfec3d..faf95b33 100644 --- a/src/js/views/levelDropdownView.js +++ b/src/js/views/levelDropdownView.js @@ -292,7 +292,7 @@ var LevelDropdownView = ContainedBase.extend({ $(selector).toggleClass('selected', value); // also go find the series and update the about - _.each(this.seriesViews, function(view) { + this.seriesViews.forEach(function(view) { if (view.levelIDs.indexOf(id) === -1) { return; } @@ -343,14 +343,14 @@ var LevelDropdownView = ContainedBase.extend({ }, updateSolvedStatus: function() { - _.each(this.seriesViews, function(view) { + this.seriesViews.forEach(function(view) { view.updateSolvedStatus(); }, this); }, buildSequences: function() { this.seriesViews = []; - _.each(this.getSequencesOnTab(), function(sequenceName) { + this.getSequencesOnTab().forEach(function(sequenceName) { this.seriesViews.push(new SeriesView({ destination: this.$el, name: sequenceName, @@ -377,7 +377,7 @@ var SeriesView = BaseView.extend({ this.levelIDs = []; var firstLevelInfo = null; - _.each(this.levels, function(level) { + this.levels.forEach(function(level) { if (firstLevelInfo === null) { firstLevelInfo = this.formatLevelAbout(level.id); } diff --git a/src/js/views/multiView.js b/src/js/views/multiView.js index d85bafb9..9a3981ae 100644 --- a/src/js/views/multiView.js +++ b/src/js/views/multiView.js @@ -142,7 +142,7 @@ var MultiView = Backbone.View.extend({ // other views will take if they need to this.keyboardListener.mute(); - _.each(this.childViews, function(childView) { + this.childViews.forEach(function(childView) { childView.die(); }); @@ -183,7 +183,7 @@ var MultiView = Backbone.View.extend({ render: function() { // go through each and render... show the first - _.each(this.childViewJSONs, function(childViewJSON, index) { + this.childViewJSONs.forEach(function(childViewJSON, index) { var childView = this.createChildView(childViewJSON); this.childViews.push(childView); this.addNavToView(childView, index); diff --git a/src/js/views/rebaseView.js b/src/js/views/rebaseView.js index accae218..b79e0b64 100644 --- a/src/js/views/rebaseView.js +++ b/src/js/views/rebaseView.js @@ -19,7 +19,7 @@ var InteractiveRebaseView = ContainedBase.extend({ this.rebaseEntries = new RebaseEntryCollection(); options.toRebase.reverse(); - _.each(options.toRebase, function(commit) { + options.toRebase.forEach(function(commit) { var id = commit.get('id'); this.rebaseMap[id] = commit; @@ -63,7 +63,7 @@ var InteractiveRebaseView = ContainedBase.extend({ // now get the real array var toRebase = []; - _.each(uiOrder, function(id) { + uiOrder.forEach(function(id) { // the model pick check if (this.entryObjMap[id].get('pick')) { toRebase.unshift(this.rebaseMap[id]); diff --git a/src/js/visuals/index.js b/src/js/visuals/index.js index 604afef6..08fe4db6 100644 --- a/src/js/visuals/index.js +++ b/src/js/visuals/index.js @@ -58,7 +58,7 @@ GitVisuals.prototype.defer = function(action) { }; GitVisuals.prototype.deferFlush = function() { - _.each(this.deferred, function(action) { + this.deferred.forEach(function(action) { action(); }, this); this.deferred = []; @@ -68,17 +68,17 @@ GitVisuals.prototype.resetAll = function() { // make sure to copy these collections because we remove // items in place and underscore is too dumb to detect length change var edges = this.visEdgeCollection.toArray(); - _.each(edges, function(visEdge) { + edges.forEach(function(visEdge) { visEdge.remove(); }, this); var branches = this.visBranchCollection.toArray(); - _.each(branches, function(visBranch) { + branches.forEach(function(visBranch) { visBranch.remove(); }, this); var tags = this.visTagCollection.toArray(); - _.each(tags, function(visTag) { + tags.forEach(function(visTag) { visTag.remove(); }, this); @@ -332,7 +332,7 @@ GitVisuals.prototype.explodeNodes = function(speed) { // are called unnecessarily when they have almost // zero speed. would be interesting to see performance differences var keepGoing = []; - _.each(funcs, function(func) { + funcs.forEach(function(func) { if (func()) { keepGoing.push(func); } @@ -485,7 +485,7 @@ GitVisuals.prototype.getBlendedHuesForCommit = function(commit) { GitVisuals.prototype.blendHuesFromBranchStack = function(branchStackArray) { var hueStrings = []; - _.each(branchStackArray, function(branchWrapper) { + branchStackArray.forEach(function(branchWrapper) { var fill = branchWrapper.obj.get('visBranch').get('fill'); if (fill.slice(0,3) !== 'hsb') { @@ -525,7 +525,7 @@ GitVisuals.prototype.getCommitUpstreamStatus = function(commit) { GitVisuals.prototype.calcTagStacks = function() { var tags = this.gitEngine.getTags(); var map = {}; - _.each(tags, function(tag) { + tags.forEach(function(tag) { var thisId = tag.target.get('id'); map[thisId] = map[thisId] || []; @@ -542,7 +542,7 @@ GitVisuals.prototype.calcTagStacks = function() { GitVisuals.prototype.calcBranchStacks = function() { var branches = this.gitEngine.getBranches(); var map = {}; - _.each(branches, function(branch) { + branches.forEach(function(branch) { var thisId = branch.target.get('id'); map[thisId] = map[thisId] || []; @@ -572,7 +572,7 @@ GitVisuals.prototype.calcWidth = function() { GitVisuals.prototype.maxWidthRecursive = function(commit) { var childrenTotalWidth = 0; - _.each(commit.get('children'), function(child) { + commit.get('children').forEach(function(child) { // only include this if we are the "main" parent of // this child if (child.isMainParent(commit)) { @@ -601,14 +601,14 @@ GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) { // basic box-flex model var totalFlex = 0; var children = commit.get('children'); - _.each(children, function(child) { + children.forEach(function(child) { if (child.isMainParent(commit)) { totalFlex += child.get('visNode').getMaxWidthScaled(); } }, this); var prevBound = min; - _.each(children, function(child, index) { + children.forEach(function(child, index) { if (!child.isMainParent(commit)) { return; } @@ -777,7 +777,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) { var children = commit.get('children'); var maxDepth = depth; - _.each(children, function(child) { + children.forEach(function(child) { var d = this.calcDepthRecursive(child, depth + 1); maxDepth = Math.max(d, maxDepth); }, this); @@ -924,7 +924,7 @@ function blendHueStrings(hueStrings) { var totalBright = 0; var length = hueStrings.length; - _.each(hueStrings, function(hueString) { + hueStrings.forEach(function(hueString) { var exploded = hueString.split('(')[1]; exploded = exploded.split(')')[0]; exploded = exploded.split(','); diff --git a/src/js/visuals/tree.js b/src/js/visuals/tree.js index 5d9b92dd..42de848c 100644 --- a/src/js/visuals/tree.js +++ b/src/js/visuals/tree.js @@ -3,7 +3,7 @@ var Backbone = require('backbone'); var VisBase = Backbone.Model.extend({ removeKeys: function(keys) { - _.each(keys, function(key) { + keys.forEach(function(key) { if (this.get(key)) { this.get(key).remove(); } @@ -25,7 +25,7 @@ var VisBase = Backbone.Model.extend({ var attr = this.getAttributes(); // safely insert this attribute into all the keys we want - _.each(keys.include, function(key) { + keys.include.forEach(function(key) { attr[key] = Object.assign( {}, attr[key], @@ -33,7 +33,7 @@ var VisBase = Backbone.Model.extend({ ); }); - _.each(keys.exclude, function(key) { + keys.exclude.forEach(function(key) { delete attr[key]; }); @@ -42,4 +42,3 @@ var VisBase = Backbone.Model.extend({ }); exports.VisBase = VisBase; - diff --git a/src/js/visuals/visBase.js b/src/js/visuals/visBase.js index 5196a575..bc4ace2a 100644 --- a/src/js/visuals/visBase.js +++ b/src/js/visuals/visBase.js @@ -3,7 +3,7 @@ var Backbone = require('backbone'); var VisBase = Backbone.Model.extend({ removeKeys: function(keys) { - _.each(keys, function(key) { + keys.forEach(function(key) { if (this.get(key)) { this.get(key).remove(); } @@ -35,14 +35,14 @@ var VisBase = Backbone.Model.extend({ }, setAttrBase: function(keys, attr, instant, speed, easing) { - _.each(keys, function(key) { + keys.forEach(function(key) { if (instant) { this.get(key).attr(attr[key]); } else { this.get(key).stop(); this.get(key).animate(attr[key], speed, easing); // some keys don't support animating too, so set those instantly here - _.forEach(this.getNonAnimateKeys(), function(nonAnimateKey) { + this.getNonAnimateKeys().forEach(function(nonAnimateKey) { if (attr[key] && attr[key][nonAnimateKey] !== undefined) { this.get(key).attr(nonAnimateKey, attr[key][nonAnimateKey]); } @@ -70,7 +70,7 @@ var VisBase = Backbone.Model.extend({ var attr = this.getAttributes(); // safely insert this attribute into all the keys we want - _.each(keys.include, function(key) { + keys.include.forEach(function(key) { attr[key] = Object.assign( {}, attr[key], @@ -78,7 +78,7 @@ var VisBase = Backbone.Model.extend({ ); }); - _.each(keys.exclude, function(key) { + keys.exclude.forEach(function(key) { delete attr[key]; }); @@ -87,4 +87,3 @@ var VisBase = Backbone.Model.extend({ }); exports.VisBase = VisBase; - diff --git a/src/js/visuals/visBranch.js b/src/js/visuals/visBranch.js index 27fadfc4..73a55305 100644 --- a/src/js/visuals/visBranch.js +++ b/src/js/visuals/visBranch.js @@ -167,7 +167,7 @@ var VisBranch = VisBase.extend({ var myArray = this.getBranchStackArray(); var index = -1; - _.each(myArray, function(branch, i) { + myArray.forEach(function(branch, i) { if (branch.obj == this.get('branch')) { index = i; } @@ -279,7 +279,7 @@ var VisBranch = VisBase.extend({ arrowInnerLow, arrowStartLow ]; - _.each(coords, function(pos) { + coords.forEach(function(pos) { pathStr += 'L' + toStringCoords(pos) + ' '; }, this); pathStr += 'z'; @@ -309,7 +309,7 @@ var VisBranch = VisBase.extend({ } var maxWidth = 0; - _.each(this.getBranchStackArray(), function(branch) { + this.getBranchStackArray().forEach(function(branch) { maxWidth = Math.max(maxWidth, getTextWidth( branch.obj.get('visBranch') )); @@ -432,7 +432,7 @@ var VisBranch = VisBase.extend({ // set CSS var keys = ['text', 'rect', 'arrow']; - _.each(keys, function(key) { + keys.forEach(function(key) { $(this.get(key).node).css(attr.css); }, this); @@ -451,7 +451,7 @@ var VisBranch = VisBase.extend({ this.get('arrow') ]; - _.each(objs, function(rObj) { + objs.forEach(function(rObj) { rObj.click(this.onClick.bind(this)); }, this); }, @@ -577,4 +577,3 @@ var VisBranchCollection = Backbone.Collection.extend({ exports.VisBranchCollection = VisBranchCollection; exports.VisBranch = VisBranch; exports.randomHueString = randomHueString; - diff --git a/src/js/visuals/visEdge.js b/src/js/visuals/visEdge.js index b47ef8de..cf1d7cea 100644 --- a/src/js/visuals/visEdge.js +++ b/src/js/visuals/visEdge.js @@ -15,7 +15,7 @@ var VisEdge = VisBase.extend({ validateAtInit: function() { var required = ['tail', 'head']; - _.each(required, function(key) { + required.forEach(function(key) { if (!this.get(key)) { throw new Error(key + ' is required!'); } diff --git a/src/js/visuals/visNode.js b/src/js/visuals/visNode.js index 6d3e5cb9..5b42138b 100644 --- a/src/js/visuals/visNode.js +++ b/src/js/visuals/visNode.js @@ -261,33 +261,33 @@ var VisNode = VisBase.extend({ }, setOutgoingEdgesOpacity: function(opacity) { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { edge.setOpacity(opacity); }); }, animateOutgoingEdgesToAttr: function(snapShot, speed, easing) { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { var attr = snapShot[edge.getID()]; edge.animateToAttr(attr); }, this); }, animateOutgoingEdges: function(speed, easing) { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { edge.animateUpdatedPath(speed, easing); }, this); }, animateOutgoingEdgesFromSnapshot: function(snapshot, speed, easing) { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { var attr = snapshot[edge.getID()]; edge.animateToAttr(attr, speed, easing); }, this); }, setOutgoingEdgesBirthPosition: function(parentCoords) { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { var headPos = edge.get('head').getScreenCoords(); var path = edge.genSmoothBezierPathStringFromCoords(parentCoords, headPos); edge.get('path').stop(); @@ -334,7 +334,7 @@ var VisNode = VisBase.extend({ } var commandStr = 'git checkout ' + this.get('commit').get('id'); var Main = require('../app'); - _.each([this.get('circle'), this.get('text')], function(rObj) { + [this.get('circle'), this.get('text')].forEach(function(rObj) { rObj.click(function() { Main.getEventBaton().trigger('commandSubmitted', commandStr); }); @@ -347,7 +347,7 @@ var VisNode = VisBase.extend({ // set the opacity on my stuff var keys = ['circle', 'text']; - _.each(keys, function(key) { + keys.forEach(function(key) { this.get(key).attr({ opacity: opacity }); @@ -371,7 +371,7 @@ var VisNode = VisBase.extend({ }, removeAllEdges: function() { - _.each(this.get('outgoingEdges'), function(edge) { + this.get('outgoingEdges').forEach(function(edge) { edge.remove(); }, this); }, diff --git a/src/js/visuals/visTag.js b/src/js/visuals/visTag.js index f11afe3a..3c22d47c 100644 --- a/src/js/visuals/visTag.js +++ b/src/js/visuals/visTag.js @@ -95,7 +95,7 @@ var VisTag = VisBase.extend({ var myArray = this.getTagStackArray(); var index = -1; - _.each(myArray, function(Tag, i) { + myArray.forEach(function(Tag, i) { if (Tag.obj == this.get('tag')) { index = i; } @@ -175,7 +175,7 @@ var VisTag = VisBase.extend({ var textNode = this.get('text').node; var maxWidth = 0; - _.each(this.getTagStackArray(), function(Tag) { + this.getTagStackArray().forEach(function(Tag) { maxWidth = Math.max(maxWidth, getTextWidth( Tag.obj.get('visTag') )); @@ -271,7 +271,7 @@ var VisTag = VisBase.extend({ // set CSS var keys = ['text', 'rect']; - _.each(keys, function(key) { + keys.forEach(function(key) { $(this.get(key).node).css(attr.css); }, this); @@ -289,7 +289,7 @@ var VisTag = VisBase.extend({ this.get('text') ]; - _.each(objs, function(rObj) { + objs.forEach(function(rObj) { rObj.click(this.onClick.bind(this)); }, this); }, @@ -405,4 +405,3 @@ var VisTagCollection = Backbone.Collection.extend({ exports.VisTagCollection = VisTagCollection; exports.VisTag = VisTag; exports.randomHueString = randomHueString; - From 96ddb5041a87cd5791fa762d259df117b5007275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 12:33:23 +0700 Subject: [PATCH 11/13] Use 'Object.values' and 'Object.keys' instead of '_.each(object)' --- src/js/commands/index.js | 13 +++++++++---- src/js/git/commands.js | 5 +++-- src/js/git/index.js | 21 +++++++++++---------- src/js/graph/treeCompare.js | 19 +++++++++++-------- src/js/level/index.js | 5 +++-- src/js/level/parseWaterfall.js | 6 ++++-- src/js/models/commandModel.js | 6 ++++-- src/js/sandbox/commands.js | 7 +++++-- src/js/stores/LevelStore.js | 3 ++- 9 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/js/commands/index.js b/src/js/commands/index.js index 64706d34..710c5ab3 100644 --- a/src/js/commands/index.js +++ b/src/js/commands/index.js @@ -102,8 +102,10 @@ var commands = { }, loop: function(callback, context) { - _.each(commandConfigs, function(commandConfig, vcs) { - _.each(commandConfig, function(config, name) { + Object.keys(commandConfigs).forEach(function(vcs) { + var commandConfig = commandConfigs[vcs]; + Object.keys(commandConfig).forEach(function(name) { + var config = commandConfig[name]; callback(config, name, vcs); }); }); @@ -116,8 +118,11 @@ var parse = function(str) { var options; // see if we support this particular command - _.each(commands.getRegexMap(), function (map, thisVCS) { - _.each(map, function(regex, thisMethod) { + var regexMap = commands.getRegexMap(); + Object.keys(regexMap).forEach(function (thisVCS) { + var map = regexMap[thisVCS]; + Object.keys(map).forEach(function(thisMethod) { + var regex = map[thisMethod]; if (regex.exec(str)) { vcs = thisVCS; method = thisMethod; diff --git a/src/js/git/commands.js b/src/js/git/commands.js index 88bf2bb5..a34cbfaf 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -839,9 +839,10 @@ var instantCommands = [ var commands = require('../commands').commands.getOptionMap()['git']; // 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); - _.each(commandOptions, function(vals, optionName) { + Object.keys(commandOptions).forEach(function(optionName) { lines.push('\t ' + optionName); }, this); }, this); diff --git a/src/js/git/index.js b/src/js/git/index.js index abbf4408..e3f8b8dd 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -280,18 +280,18 @@ GitEngine.prototype.instantiateFromTree = function(tree) { // now we do the loading part var createdSoFar = {}; - _.each(tree.commits, function(commitJSON) { + Object.values(tree.commits).forEach(function(commitJSON) { var commit = this.getOrMakeRecursive(tree, createdSoFar, commitJSON.id, this.gitVisuals); this.commitCollection.add(commit); }, this); - _.each(tree.branches, function(branchJSON) { + Object.values(tree.branches).forEach(function(branchJSON) { var branch = this.getOrMakeRecursive(tree, createdSoFar, branchJSON.id, this.gitVisuals); this.branchCollection.add(branch, {silent: true}); }, this); - _.each(tree.tags, function(tagJSON) { + Object.values(tree.tags || {}).forEach(function(tagJSON) { var tag = this.getOrMakeRecursive(tree, createdSoFar, tagJSON.id, this.gitVisuals); this.tagCollection.add(tag, {silent: true}); @@ -360,7 +360,8 @@ GitEngine.prototype.makeOrigin = function(treeString) { var originTree = JSON.parse(unescape(treeString)); // make an origin branch for each branch mentioned in the tree if its // 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]) { // we already have this branch return; @@ -1802,7 +1803,7 @@ GitEngine.prototype.updateBranchesForHg = function(branchList) { GitEngine.prototype.updateCommitParentsForHgRebase = function(commitSet) { var anyChange = false; - _.each(commitSet, function(val, commitID) { + Object.keys(commitSet).forEach(function(commitID) { var commit = this.refs[commitID]; var thisUpdated = commit.checkForUpdatedParent(this); anyChange = anyChange || thisUpdated; @@ -1819,7 +1820,7 @@ GitEngine.prototype.pruneTree = function() { var set = this.getUpstreamBranchSet(); // don't prune commits that HEAD depends on var headSet = Graph.getUpstreamSet(this, 'HEAD'); - _.each(headSet, function(val, commitID) { + Object.keys(headSet).forEach(function(commitID) { set[commitID] = true; }); @@ -2066,14 +2067,14 @@ GitEngine.prototype.hgRebase = function(destination, base) { // and NOWWWwwww get all the descendants of this set var moreSets = []; - _.each(upstream, function(val, id) { + Object.keys(upstream).forEach(function(id) { moreSets.push(this.getDownstreamSet(id)); }, this); var masterSet = {}; masterSet[baseCommit.get('id')] = true; [upstream, downstream].concat(moreSets).forEach(function(set) { - _.each(set, function(val, id) { + Object.keys(set).forEach(function(id) { masterSet[id] = true; }); }); @@ -2081,7 +2082,7 @@ GitEngine.prototype.hgRebase = function(destination, base) { // we also need the branches POINTING to master set var branchMap = {}; var upstreamSet = this.getUpstreamBranchSet(); - _.each(masterSet, function(val, commitID) { + Object.keys(masterSet).forEach(function(commitID) { // now loop over that commits branches upstreamSet[commitID].forEach(function(branchJSON) { branchMap[branchJSON.id] = true; @@ -2305,7 +2306,7 @@ GitEngine.prototype.filterRebaseCommits = function( options ) { var changesAlreadyMade = {}; - _.each(stopSet, function(val, key) { + Object.keys(stopSet).forEach(function(key) { changesAlreadyMade[this.scrapeBaseID(key)] = true; }, this); var uniqueIDs = {}; diff --git a/src/js/graph/treeCompare.js b/src/js/graph/treeCompare.js index 6318a3ec..9b37bc60 100644 --- a/src/js/graph/treeCompare.js +++ b/src/js/graph/treeCompare.js @@ -145,8 +145,7 @@ TreeCompare.compareAllBranchesWithinTreesHashAgnostic = function(treeA, treeB) { treeA.branches, treeB.branches ); - var branchNames = []; - _.each(allBranches, function(obj, name) { branchNames.push(name); }); + var branchNames = Object.keys(allBranches || {}); return this.compareBranchesWithinTreesHashAgnostic(treeA, treeB, branchNames); }; @@ -188,7 +187,8 @@ TreeCompare.compareBranchesWithinTreesHashAgnostic = function(treeA, treeB, bran TreeCompare.evalAsserts = function(tree, assertsPerBranch) { 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); }, this); return result; @@ -327,9 +327,10 @@ TreeCompare.lowercaseTree = function(tree) { tree.HEAD.target = tree.HEAD.target.toLocaleLowerCase(); } - var branches = tree.branches; + var 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(); tree.branches[name.toLocaleLowerCase()] = obj; }); @@ -378,7 +379,8 @@ TreeCompare.reduceTreeFields = function(trees) { }; trees.forEach(function(tree) { - _.each(treeDefaults, function(val, key) { + Object.keys(treeDefaults).forEach(function(key) { + var val = treeDefaults[key]; if (tree[key] === undefined) { tree[key] = val; } @@ -388,7 +390,8 @@ TreeCompare.reduceTreeFields = function(trees) { // this function saves only the specified fields of a tree var saveOnly = function(tree, treeKey, saveFields, sortFields) { 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 var blank = {}; saveFields.forEach(function(field) { @@ -399,7 +402,7 @@ TreeCompare.reduceTreeFields = function(trees) { } }); - _.each(sortFields, function(field) { + Object.values(sortFields || {}).forEach(function(field) { // also sort some fields if (obj[field]) { obj[field].sort(); diff --git a/src/js/level/index.js b/src/js/level/index.js index e2801d6e..d8737456 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -406,8 +406,9 @@ var Level = Sandbox.extend({ } var matched = false; - _.each(Commands.commands.getCommandsThatCount(), function(map) { - _.each(map, function(regex) { + var commandsThatCount = Commands.commands.getCommandsThatCount(); + Object.values(commandsThatCount).forEach(function(map) { + Object.values(map).forEach(function(regex) { matched = matched || regex.test(command.get('rawStr')); }); }); diff --git a/src/js/level/parseWaterfall.js b/src/js/level/parseWaterfall.js index d84fde97..b457893d 100644 --- a/src/js/level/parseWaterfall.js +++ b/src/js/level/parseWaterfall.js @@ -75,8 +75,10 @@ ParseWaterfall.prototype.expandAllShortcuts = function(commandStr) { }; ParseWaterfall.prototype.expandShortcut = function(commandStr, shortcutMap) { - _.each(shortcutMap, function(map, vcs) { - _.each(map, function(regex, method) { + Object.keys(shortcutMap).forEach(function(vcs) { + var map = shortcutMap[vcs]; + Object.keys(map).forEach(function(method) { + var regex = map[method]; var results = regex.exec(commandStr); if (results) { commandStr = vcs + ' ' + method + ' ' + commandStr.slice(results[0].length); diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index b8a9569f..7e011896 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -82,7 +82,8 @@ var Command = Backbone.Model.extend({ return this.replaceDotWithHead(arg); }, this); var newMap = {}; - _.each(options, function(args, key) { + Object.keys(options).forEach(function(key) { + var args = options[key]; newMap[key] = Object.values(args).map(function (arg) { return this.replaceDotWithHead(arg); }, this); @@ -273,7 +274,8 @@ var Command = Backbone.Model.extend({ 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 // options (etc) that need to be set this.set(key, obj); diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 8e3f57b1..27151ee2 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -139,8 +139,11 @@ var getAllCommands = function() { require('../level').regexMap, regexMap ); - _.each(Commands.commands.getRegexMap(), function(map, vcs) { - _.each(map, function(regex, method) { + var mRegexMap = Commands.commands.getRegexMap(); + Object.keys(mRegexMap).forEach(function(vcs) { + var map = mRegexMap[vcs]; + Object.keys(map).forEach(function(method) { + var regex = map[method]; allCommands[vcs + ' ' + method] = regex; }); }); diff --git a/src/js/stores/LevelStore.js b/src/js/stores/LevelStore.js index 9f951b06..c5e1a7ba 100644 --- a/src/js/stores/LevelStore.js +++ b/src/js/stores/LevelStore.js @@ -52,7 +52,8 @@ var validateLevel = function(level) { /** * Unpack the level sequences. */ -_.each(levelSequences, function(levels, levelSequenceName) { +Object.keys(levelSequences).forEach(function(levelSequenceName) { + var levels = levelSequences[levelSequenceName]; _sequences.push(levelSequenceName); if (!levels || !levels.length) { throw new Error('no empty sequences allowed'); From 9365454cf36f8f1e9be43839afada0c03b60a592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 12:51:15 +0700 Subject: [PATCH 12/13] Use 'Array.prototype.includes' instead of '_.include' --- src/js/visuals/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/visuals/index.js b/src/js/visuals/index.js index 08fe4db6..80d2d806 100644 --- a/src/js/visuals/index.js +++ b/src/js/visuals/index.js @@ -354,7 +354,7 @@ GitVisuals.prototype.explodeNodes = function(speed) { GitVisuals.prototype.animateAllFromAttrToAttr = function(fromSnapshot, toSnapshot, idsToOmit) { var animate = function(obj) { var id = obj.getID(); - if (_.include(idsToOmit, id)) { + if (idsToOmit.includes(id)) { return; } From 27ef578b2ebc83865f0a4282616869b937da534d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EF=BC=A8=EF=BD=8F=EF=BD=8E=EF=BD=87=EF=BD=81=EF=BD=92?= =?UTF-8?q?=EF=BD=83?= Date: Sat, 1 Dec 2018 13:04:24 +0700 Subject: [PATCH 13/13] Remove 16 underscore requires --- src/js/commands/index.js | 1 - src/js/git/commands.js | 1 - src/js/git/index.js | 1 - src/js/graph/index.js | 2 -- src/js/level/builder.js | 1 - src/js/level/index.js | 1 - src/js/level/parseWaterfall.js | 2 -- src/js/models/commandModel.js | 1 - src/js/sandbox/commands.js | 1 - src/js/views/commandViews.js | 1 - src/js/visuals/tree.js | 1 - src/js/visuals/visBase.js | 1 - src/js/visuals/visBranch.js | 1 - src/js/visuals/visEdge.js | 1 - src/js/visuals/visNode.js | 1 - src/js/visuals/visTag.js | 1 - 16 files changed, 18 deletions(-) diff --git a/src/js/commands/index.js b/src/js/commands/index.js index 710c5ab3..95011224 100644 --- a/src/js/commands/index.js +++ b/src/js/commands/index.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var intl = require('../intl'); var Errors = require('../util/errors'); diff --git a/src/js/git/commands.js b/src/js/git/commands.js index a34cbfaf..4c083d5e 100644 --- a/src/js/git/commands.js +++ b/src/js/git/commands.js @@ -1,5 +1,4 @@ var escapeString = require('../util/escapeString'); -var _ = require('underscore'); var intl = require('../intl'); var Graph = require('../graph'); diff --git a/src/js/git/index.js b/src/js/git/index.js index e3f8b8dd..d03a2075 100644 --- a/src/js/git/index.js +++ b/src/js/git/index.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Q = require('q'); diff --git a/src/js/graph/index.js b/src/js/graph/index.js index 584f788d..2eaf6cab 100644 --- a/src/js/graph/index.js +++ b/src/js/graph/index.js @@ -1,5 +1,3 @@ -var _ = require('underscore'); - function invariant(truthy, reason) { if (!truthy) { throw new Error(reason); diff --git a/src/js/level/builder.js b/src/js/level/builder.js index a5a848a6..63ebdef9 100644 --- a/src/js/level/builder.js +++ b/src/js/level/builder.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Q = require('q'); diff --git a/src/js/level/index.js b/src/js/level/index.js index d8737456..4bac1b5b 100644 --- a/src/js/level/index.js +++ b/src/js/level/index.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Q = require('q'); var util = require('../util'); diff --git a/src/js/level/parseWaterfall.js b/src/js/level/parseWaterfall.js index b457893d..b58e7e00 100644 --- a/src/js/level/parseWaterfall.js +++ b/src/js/level/parseWaterfall.js @@ -1,5 +1,3 @@ -var _ = require('underscore'); - var GitCommands = require('../git/commands'); var Commands = require('../commands'); var SandboxCommands = require('../sandbox/commands'); diff --git a/src/js/models/commandModel.js b/src/js/models/commandModel.js index 7e011896..76e94d61 100644 --- a/src/js/models/commandModel.js +++ b/src/js/models/commandModel.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Errors = require('../util/errors'); diff --git a/src/js/sandbox/commands.js b/src/js/sandbox/commands.js index 27151ee2..8b913564 100644 --- a/src/js/sandbox/commands.js +++ b/src/js/sandbox/commands.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var util = require('../util'); var constants = require('../util/constants'); diff --git a/src/js/views/commandViews.js b/src/js/views/commandViews.js index 8dfa71ef..b47d4bfa 100644 --- a/src/js/views/commandViews.js +++ b/src/js/views/commandViews.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var Main = require('../app'); diff --git a/src/js/visuals/tree.js b/src/js/visuals/tree.js index 42de848c..ad270a60 100644 --- a/src/js/visuals/tree.js +++ b/src/js/visuals/tree.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var VisBase = Backbone.Model.extend({ diff --git a/src/js/visuals/visBase.js b/src/js/visuals/visBase.js index bc4ace2a..fb6a68a1 100644 --- a/src/js/visuals/visBase.js +++ b/src/js/visuals/visBase.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var VisBase = Backbone.Model.extend({ diff --git a/src/js/visuals/visBranch.js b/src/js/visuals/visBranch.js index 73a55305..ddac02f4 100644 --- a/src/js/visuals/visBranch.js +++ b/src/js/visuals/visBranch.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var GRAPHICS = require('../util/constants').GRAPHICS; diff --git a/src/js/visuals/visEdge.js b/src/js/visuals/visEdge.js index cf1d7cea..355efcf4 100644 --- a/src/js/visuals/visEdge.js +++ b/src/js/visuals/visEdge.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var GRAPHICS = require('../util/constants').GRAPHICS; diff --git a/src/js/visuals/visNode.js b/src/js/visuals/visNode.js index 5b42138b..f9952d29 100644 --- a/src/js/visuals/visNode.js +++ b/src/js/visuals/visNode.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var GRAPHICS = require('../util/constants').GRAPHICS; diff --git a/src/js/visuals/visTag.js b/src/js/visuals/visTag.js index 3c22d47c..d07f7435 100644 --- a/src/js/visuals/visTag.js +++ b/src/js/visuals/visTag.js @@ -1,4 +1,3 @@ -var _ = require('underscore'); var Backbone = require('backbone'); var GRAPHICS = require('../util/constants').GRAPHICS;