mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-12 20:09:46 +02:00
Replace lodash with specific implementations, #1389
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import _ from 'lodash';
|
||||
import randomString from 'crypto-random-string';
|
||||
|
||||
import { logger } from '../../logger';
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
Reference in New Issue
Block a user