-
Notifications
You must be signed in to change notification settings - Fork 21
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
fix(lodash): Remove dependency on lodash #144
Conversation
const pointsStringFromPoints = (points: [number, number][]): string => | ||
_.reduce(points, (result: string, nextPoint: [number, number]) => `${result} ${nextPoint[0]},${nextPoint[1]}`, ''); | ||
points?.reduce((result: string, nextPoint: [number, number]) => `${result} ${nextPoint[0]},${nextPoint[1]}`, '') ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are types not strict enough to know if points
is potentially undefined?
If they are, then we don't need points?.
it can simply be points.
Looks like getConnectorBoundingBox
has a bad return type and we cannot rely on types :( Please address that return type.
@@ -55,7 +54,7 @@ const DefaultConnectorTerminal: React.FunctionComponent<EdgeConnectorArrowProps> | |||
return null; | |||
} | |||
const bendPoints = edge.getBendpoints(); | |||
const startPoint = isTarget ? _.last(bendPoints) || edge.getStartPoint() : _.head(bendPoints) || edge.getEndPoint(); | |||
const startPoint = isTarget ? bendPoints?.[bendPoints.length - 1] || edge.getStartPoint() : bendPoints?.[0] || edge.getEndPoint(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid unnecessary ?
.
const startPoint = isTarget ? bendPoints?.[bendPoints.length - 1] || edge.getStartPoint() : bendPoints?.[0] || edge.getEndPoint(); | |
const startPoint = isTarget ? bendPoints.[bendPoints.length - 1] || edge.getStartPoint() : bendPoints.[0] || edge.getEndPoint(); |
@@ -54,19 +53,27 @@ export function computeLabelLocation(points: PointWithSize[]): PointWithSize { | |||
let lowPoints: PointWithSize[]; | |||
const threshold = 5; | |||
|
|||
_.forEach(points, p => { | |||
points?.forEach(p => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
points?.forEach(p => { | |
points.forEach(p => { |
@@ -60,7 +59,7 @@ export default abstract class BaseElement<E extends ElementModel = ElementModel, | |||
controller: observable.ref, | |||
label: observable, | |||
style: observable, | |||
ordering: computed({ equals: _.isEqual }) | |||
ordering: computed({ equals: (a, b) => JSON.stringify(a || {}) === JSON.stringify(b || {}) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one concerns me a bit.
ordering
is an array of numbers. Can we make a specific comparison function.
layoutNode = _.find(nodes, { id: node.getChildren()[0].getId() }); | ||
let layoutNode = nodes.find(n => n.id === node.getId()); | ||
if (!layoutNode && node.getNodes().length) { | ||
layoutNode = nodes.find(n => n.id === node.getChildren()[0].getId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC for mobx performance, you'll want to cache the id instead of traversing the observables.
layoutNode = nodes.find(n => n.id === node.getChildren()[0].getId()); | |
const id = node.getChildren()[0].getId(); | |
layoutNode = nodes.find(n => n.id === id); |
@@ -42,7 +41,7 @@ export class DagreLayout extends BaseLayout implements Layout { | |||
} | |||
|
|||
protected updateEdgeBendpoints(edges: DagreLink[]): void { | |||
_.forEach(edges, edge => { | |||
edges?.forEach(edge => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be
edges?.forEach(edge => { | |
edges.forEach(edge => { |
|
||
if (!this.dagreOptions.ignoreGroups) { | ||
_.forEach(this.groups, group => { | ||
this.groups?.forEach(group => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be:
this.groups?.forEach(group => { | |
this.groups.forEach(group => { |
@@ -88,7 +86,7 @@ const createAggregateEdges = ( | |||
return newEdges; | |||
}, | |||
[] as EdgeModel[] | |||
); | |||
) ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for the return value to be undefined
here.
import { GraphElement, Node, isNode, isGraph, NodeStyle } from '../types'; | ||
|
||
const groupNodeElements = (nodes: GraphElement[]): Node[] => { | ||
if (!_.size(nodes)) { | ||
if (!nodes?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be:
if (!nodes?.length) { | |
if (!nodes.length) { |
} | ||
); | ||
} | ||
const children: GraphElement[] = nodeElements.getChildren()?.filter(e => isNode(e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think children can be undefined
here.
fd920f7
to
6beecab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
6beecab
to
4214194
Compare
4214194
to
b0c87aa
Compare
🎉 This PR is included in version 5.3.0-prerelease.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What
Closes #128
Description
Removes dependency on lodash
Type of change
/cc @christianvogt