Skip to content

Commit

Permalink
refactor: remove built-in uniqBy and deepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Jun 25, 2023
1 parent 8091f60 commit 7bdd586
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 148 deletions.
10 changes: 4 additions & 6 deletions packages/graphin/src/Graphin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import GraphinContext from './GraphinContext';
/** 内置布局 */
import LayoutController from './layout';
import { getDefaultStyleByTheme, ThemeData } from './theme/index';

import { cloneDeep, isEqual } from 'lodash-es';
/** types */
import { cloneDeep } from 'lodash-es';
import { GraphinData, GraphinProps, GraphinTreeData, IconLoader, IUserNode, PlainObject } from './typings/type';
import type { GraphinData, GraphinProps, GraphinTreeData, IconLoader, IUserNode, PlainObject } from './typings/type';
/** utils */
// import shallowEqual from './utils/shallowEqual';
import deepEqual from './utils/deepEqual';
import { processLayoutConfig } from './utils/layout';

const { DragCanvas, ZoomCanvas, DragNode, DragCombo, ClickSelect, BrushSelect, ResizeCanvas } = Behaviors;
Expand Down Expand Up @@ -548,8 +547,7 @@ class Graphin extends React.PureComponent<GraphinProps, GraphinState> {
/* eslint-disable react/destructuring-assignment */
const prevVal = prevProps[key];
const currentVal = this.props[key] as DiffValue;
const isEqual = deepEqual(prevVal, currentVal);
return !isEqual;
return !isEqual(prevVal, currentVal);
}

render() {
Expand Down
5 changes: 2 additions & 3 deletions packages/graphin/src/layout/utils/graph.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable import/prefer-default-export */
import { Edge } from '../../layout/force/Elements';
import { IUserNode as Node } from '../../typings/type';
import Utils from '../../utils/index';
import Vector from '../force/Vector';
import { uniqBy } from 'lodash-es';

const getDegree = (node: Node, edges: Edge[]) => {
const nodeId = node.data.id;
Expand Down Expand Up @@ -71,7 +70,7 @@ const getRelativeNodes = (type: 'source' | 'target' | 'both', coreNode: Node, ed
break;
}
// 去重
relativeNodes = Utils.uniqBy(relativeNodes, (a: Node, b: Node) => {
relativeNodes = uniqBy(relativeNodes, (a: Node, b: Node) => {
return a.id === b.id;
});
return relativeNodes;
Expand Down
9 changes: 0 additions & 9 deletions packages/graphin/src/utils/Tree.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { GraphinTreeData } from '../typings/type';

// export interface Node {
// id: string;
// parent?: Node;
// data?: any; // eslint-disable-line
// children: Node[];
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// [key: string]: any;
// }

export interface Node extends GraphinTreeData {
parent?: Node;
}
Expand Down
81 changes: 0 additions & 81 deletions packages/graphin/src/utils/__tests__/deepEqual.test.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/graphin/src/utils/array.ts

This file was deleted.

39 changes: 0 additions & 39 deletions packages/graphin/src/utils/deepEqual.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/graphin/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { uniqBy } from 'lodash-es';
import { layouts } from '../layout/utils/options';
import getComboStyleByTheme from '../theme/combo-style';
import getEdgeStyleByTheme from '../theme/edge-style';
import getNodeStyleByTheme from '../theme/node-style';
import { uniqBy } from './array';
import calcByteLength from './calcByteLength';
import debug from './debug';
import hexToRgba, { hexToRgbaToHex } from './hexToRgba';
Expand Down

0 comments on commit 7bdd586

Please sign in to comment.