Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lodash with specific implementations #1392

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"dagre-d3": "^0.6.4",
"graphlib": "^2.1.7",
"he": "^1.2.0",
"lodash": "^4.17.11",
"minify": "^4.1.1",
"moment-mini": "^2.22.1",
"scope-css": "^1.2.1"
Expand Down
23 changes: 19 additions & 4 deletions src/diagrams/git/gitGraphAst.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import randomString from 'crypto-random-string';

import { logger } from '../../logger';
Expand Down Expand Up @@ -43,6 +42,18 @@ function isReachableFrom(currentCommit, otherCommit) {
return false;
}

function uniqBy(list, fn) {
const recordMap = Object.create(null);
return list.reduce((out, item) => {
const key = fn(item);
if (!recordMap[key]) {
recordMap[key] = true;
out.push(item);
}
return out;
}, []);
}

export const setDirection = function(dir) {
direction = dir;
};
Expand Down Expand Up @@ -142,7 +153,10 @@ function upsert(arr, key, newval) {
}

function prettyPrintCommitHistory(commitArr) {
const commit = _.maxBy(commitArr, 'seq');
const commit = commitArr.reduce((out, commit) => {
if (out.seq > commit.seq) return out;
return commit;
}, commitArr[0]);
let line = '';
commitArr.forEach(function(c) {
if (c === commit) {
Expand All @@ -166,7 +180,7 @@ function prettyPrintCommitHistory(commitArr) {
const nextCommit = commits[commit.parent];
upsert(commitArr, commit, nextCommit);
}
commitArr = _.uniqBy(commitArr, 'id');
commitArr = uniqBy(commitArr, c => c.id);
prettyPrintCommitHistory(commitArr);
}

Expand Down Expand Up @@ -205,7 +219,8 @@ export const getCommitsArray = function() {
commitArr.forEach(function(o) {
logger.debug(o.id);
});
return _.orderBy(commitArr, ['seq'], ['desc']);
commitArr.sort((a, b) => b.seq - a.seq);
return commitArr;
};
export const getCurrentBranch = function() {
return curBranch;
Expand Down
3 changes: 1 addition & 2 deletions src/diagrams/git/gitGraphRenderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { curveBasis, line, select } from 'd3';
import _ from 'lodash';

import db from './gitGraphAst';
import gitGraphParser from './parser/gitGraph';
Expand Down Expand Up @@ -307,7 +306,7 @@ export const draw = function(txt, id, ver) {
// Parse the graph definition
parser.parse(txt + '\n');

config = _.assign(config, apiConfig, db.getOptions());
config = Object.assign(config, apiConfig, db.getOptions());
logger.debug('effective options', config);
const direction = db.getDirection();
allCommitsDict = db.getCommits();
Expand Down