Skip to content

Commit

Permalink
Bug 1467975 - Convert lodash .each() to native ES6 JS (#3699)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-srinivas authored and Cameron Dawson committed Jul 17, 2018
1 parent 33bb723 commit a664f8c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
6 changes: 3 additions & 3 deletions ui/js/controllers/perf/graphs.js
Expand Up @@ -157,13 +157,13 @@ perf.controller('GraphsCtrl', [

// Get revision information for both this datapoint and the previous
// one
_.each([{
[{
resultSetId: dataPoint.resultSetId,
scopeKey: 'revision',
}, {
resultSetId: prevResultSetId,
scopeKey: 'prevRevision',
}], function (resultRevision) {
}].forEach((resultRevision) => {
ThResultSetModel.getRevisions(
phSeries.projectName, resultRevision.resultSetId,
).then(function (revisions) {
Expand Down Expand Up @@ -427,7 +427,7 @@ perf.controller('GraphsCtrl', [

// highlight each explicitly highlighted revision on visible serii
var highlightPromises = [];
_.each($scope.highlightedRevisions, function (rev) {
$scope.highlightedRevisions.forEach((rev) => {
if (rev && rev.length === 12) {
highlightPromises = _.union(
highlightPromises, $scope.seriesList.map(function (series) {
Expand Down
17 changes: 6 additions & 11 deletions ui/js/models/repository.js
Expand Up @@ -36,9 +36,9 @@ treeherder.factory('ThRepositoryModel', [
const groups = $rootScope.repos.reduce((acc, repo, idx, arr, group = repo => repo.repository_group.name) => (
{ ...acc, [group(repo)]: [...acc[group(repo)] || [], repo] }
), {});
_.each(groups, function (reposAr, gName) {
orderedRepoGroups[thRepoGroupOrder[gName] || gName] = { name: gName, repos: reposAr };
});
Object.entries(groups).forEach(([reposAr, gName]) => {
orderedRepoGroups[thRepoGroupOrder[reposAr] || reposAr] = { name: reposAr, repos: gName };
});
}
}
return orderedRepoGroups;
Expand Down Expand Up @@ -144,9 +144,7 @@ treeherder.factory('ThRepositoryModel', [
// controllers, etc, are watching the reference to it, which would
// be lost by replacing.
if (watchedRepos.length <= 1) {
_.each(watchedRepos, function (r, rname) {
unwatchRepo(rname);
});
watchedRepos.forEach(rname => unwatchRepo(rname));
}
if (!_.has(watchedRepos, name)) {
watchRepo(name);
Expand Down Expand Up @@ -212,8 +210,7 @@ treeherder.factory('ThRepositoryModel', [

$rootScope.repos = data.map(datum => new Repo(datum));

_.each(data, addRepoAsUnwatched);

data.forEach(repo => addRepoAsUnwatched(repo));
// This needs to be done before `setCurrent` because
// `setCurrent` overwrites the entire listing
// with only the default repo
Expand All @@ -237,9 +234,7 @@ treeherder.factory('ThRepositoryModel', [
storedWatched.reverse();
storedWatched.push(options.name);

_.each(storedWatched, function (repo) {
watchRepo(repo);
});
storedWatched.forEach(repo => watchRepo(repo));
}
saveWatchedRepos();
}
Expand Down
8 changes: 4 additions & 4 deletions ui/js/models/resultsets_store.js
Expand Up @@ -306,7 +306,7 @@ treeherder.factory('ThResultSetStore', [
getGeckoDecisionTaskId(push.id).then(function (decisionTaskId) {
return RunnableJobModel.getList(repoData.name, { decision_task_id: decisionTaskId }).then(function (jobList) {
var id = push.id;
_.each(jobList, function (job) {
jobList.forEach((job) => {
job.result_set_id = id;
job.id = escapeId(job.result_set_id + job.ref_data_name);
});
Expand Down Expand Up @@ -678,7 +678,7 @@ treeherder.factory('ThResultSetStore', [
// the latest ``push_timestamp`` and theoretically we could
// get
var newResultsets = [];
_.each(data.results, function (rs) {
data.results.forEach((rs) => {
if (rsIds.indexOf(rs.id) === -1) {
newResultsets.push(rs);
}
Expand Down Expand Up @@ -957,8 +957,8 @@ treeherder.factory('ThResultSetStore', [
};

var sortGroupedJobs = function (groupedJobs) {
_.each(groupedJobs.platforms, function (platform) {
_.each(platform.groups, function (group) {
groupedJobs.platforms.forEach((platform) => {
platform.groups.forEach((group) => {
group.jobs = _.sortBy(group.jobs, function (job) {
// Symbol could be something like 1, 2 or 3. Or A, B, C or R1,
// R2, R10.
Expand Down
7 changes: 3 additions & 4 deletions ui/js/services/jobfilters.js
Expand Up @@ -172,7 +172,7 @@ treeherder.factory('thJobFilters', [
_.mapKeys(DEFAULTS, function (value, key) {
return _withPrefix(key);
}));
_.each(locationSearch, function (values, field) {
Object.entries(locationSearch).forEach(([field, values]) => {
if (_isFieldFilter(field)) {
if (field === QS_SEARCH_STR) {
// we cache this one a little differently
Expand Down Expand Up @@ -420,11 +420,10 @@ treeherder.factory('thJobFilters', [
*/
function getFieldFiltersArray() {
const fieldFilters = [];

_.each($location.search(), function (values, fieldName) {
Object.entries($location.search()).forEach(([fieldName, values]) => {
if (_isFieldFilter(fieldName)) {
const valArr = _toArray(values);
_.each(valArr, function (val) {
valArr.forEach((val) => {
if (fieldName !== QS_SEARCH_STR) {
fieldFilters.push({
field: _withoutPrefix(fieldName),
Expand Down

0 comments on commit a664f8c

Please sign in to comment.