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

fix(lodash): Remove dependency on lodash #144

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

jeff-phillips-18
Copy link
Member

What

Closes #128

Description

Removes dependency on lodash

Type of change

  • Refactoring (no functional changes, no api changes)

/cc @christianvogt

Comment on lines 17 to 18
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]}`, '') ?? '';
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unnecessary ?.

Suggested change
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 => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 || {}) })
Copy link
Collaborator

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());
Copy link
Collaborator

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.

Suggested change
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 => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be

Suggested change
edges?.forEach(edge => {
edges.forEach(edge => {


if (!this.dagreOptions.ignoreGroups) {
_.forEach(this.groups, group => {
this.groups?.forEach(group => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be:

Suggested change
this.groups?.forEach(group => {
this.groups.forEach(group => {

@@ -88,7 +86,7 @@ const createAggregateEdges = (
return newEdges;
},
[] as EdgeModel[]
);
) ?? [];
Copy link
Collaborator

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be:

Suggested change
if (!nodes?.length) {
if (!nodes.length) {

}
);
}
const children: GraphElement[] = nodeElements.getChildren()?.filter(e => isNode(e));
Copy link
Collaborator

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.

Copy link
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeff-phillips-18 jeff-phillips-18 merged commit bed1c18 into patternfly:main Feb 16, 2024
7 checks passed
@jeff-phillips-18 jeff-phillips-18 deleted the rm-lodash branch February 16, 2024 17:55
Copy link

🎉 This PR is included in version 5.3.0-prerelease.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove lodash dependency
4 participants