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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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