Skip to content

Commit b7090dd

Browse files
authored
Refactor/clean link component (#139)
* Remove unnecessary props x1, x2, y1 and y2 from Link * Rename utils/isObjectEmpty to isEmptyObject
1 parent 390e5d5 commit b7090dd

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

src/components/graph/graph.helper.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
297297
d,
298298
source,
299299
target,
300-
x1,
301-
y1,
302-
x2,
303-
y2,
304300
strokeWidth,
305301
stroke,
306302
mouseCursor: config.link.mouseCursor,
@@ -434,7 +430,7 @@ function checkForGraphElementsChanges(nextProps, currentState) {
434430
function checkForGraphConfigChanges(nextProps, currentState) {
435431
const newConfig = nextProps.config || {};
436432
const configUpdated =
437-
newConfig && !utils.isObjectEmpty(newConfig) && !utils.isDeepEqual(newConfig, currentState.config);
433+
newConfig && !utils.isEmptyObject(newConfig) && !utils.isDeepEqual(newConfig, currentState.config);
438434
const d3ConfigUpdated = newConfig && newConfig.d3 && !utils.isDeepEqual(newConfig.d3, currentState.config.d3);
439435

440436
return { configUpdated, d3ConfigUpdated };

src/components/link/Link.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ import React from 'react';
2323
* d="M1..."
2424
* source='idSourceNode'
2525
* target='idTargetNode'
26-
* x1=22
27-
* y1=22
28-
* x2=22
29-
* y2=22
3026
* markerId='marker-small'
3127
* strokeWidth=1.5
3228
* stroke='green'

src/utils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MAX_DEPTH = 20;
1717
* @memberof utils
1818
*/
1919
function _isPropertyNestedObject(o, k) {
20-
return o.hasOwnProperty(k) && typeof o[k] === 'object' && o[k] !== null && !isObjectEmpty(o[k]);
20+
return o.hasOwnProperty(k) && typeof o[k] === 'object' && o[k] !== null && !isEmptyObject(o[k]);
2121
}
2222

2323
/**
@@ -35,7 +35,7 @@ function isDeepEqual(o1, o2, _depth = 0) {
3535
return true;
3636
}
3737

38-
if ((isObjectEmpty(o1) && !isObjectEmpty(o2)) || (!isObjectEmpty(o1) && isObjectEmpty(o2))) {
38+
if ((isEmptyObject(o1) && !isEmptyObject(o2)) || (!isEmptyObject(o1) && isEmptyObject(o2))) {
3939
return false;
4040
}
4141

@@ -52,7 +52,7 @@ function isDeepEqual(o1, o2, _depth = 0) {
5252
if (nestedO && _depth < MAX_DEPTH) {
5353
diffs.push(isDeepEqual(o1[k], o2[k], _depth + 1));
5454
} else {
55-
const r = (isObjectEmpty(o1[k]) && isObjectEmpty(o2[k])) || (o2.hasOwnProperty(k) && o2[k] === o1[k]);
55+
const r = (isEmptyObject(o1[k]) && isEmptyObject(o2[k])) || (o2.hasOwnProperty(k) && o2[k] === o1[k]);
5656

5757
diffs.push(r);
5858

@@ -72,7 +72,7 @@ function isDeepEqual(o1, o2, _depth = 0) {
7272
* @returns {boolean} true if the given object is n ft and object and is empty.
7373
* @memberof utils
7474
*/
75-
function isObjectEmpty(o) {
75+
function isEmptyObject(o) {
7676
return !!o && typeof o === 'object' && !Object.keys(o).length;
7777
}
7878

@@ -90,7 +90,7 @@ function merge(o1 = {}, o2 = {}, _depth = 0) {
9090
let o = {};
9191

9292
if (Object.keys(o1 || {}).length === 0) {
93-
return o2 && !isObjectEmpty(o2) ? o2 : {};
93+
return o2 && !isEmptyObject(o2) ? o2 : {};
9494
}
9595

9696
for (let k of Object.keys(o1)) {
@@ -155,7 +155,7 @@ function throwErr(component, msg) {
155155

156156
export default {
157157
isDeepEqual,
158-
isObjectEmpty,
158+
isEmptyObject,
159159
merge,
160160
pick,
161161
antiPick,

test/component/graph/graph.helper.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
describe('Graph Helper', () => {
1717
beforeAll(() => {
1818
utils.isDeepEqual = jest.fn();
19-
utils.isObjectEmpty = jest.fn();
19+
utils.isEmptyObject = jest.fn();
2020
utils.merge = jest.fn();
2121
utils.throwErr = jest.fn();
2222
jest.spyOn(linkHelper, 'buildLinkPathDefinition');

test/utils.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ describe('Utils', () => {
4545
});
4646
});
4747

48-
describe('#isObjectEmpty', () => {
48+
describe('#isEmptyObject', () => {
4949
test('should properly check whether the object is empty or not', () => {
50-
expect(utils.isObjectEmpty({ a: 1, b: {} })).toEqual(false);
51-
expect(utils.isObjectEmpty({ a: 1 })).toEqual(false);
52-
expect(utils.isObjectEmpty(null)).toEqual(false);
53-
expect(utils.isObjectEmpty(undefined)).toEqual(false);
54-
expect(utils.isObjectEmpty(0)).toEqual(false);
55-
expect(utils.isObjectEmpty('test')).toEqual(false);
56-
expect(utils.isObjectEmpty({})).toEqual(true);
50+
expect(utils.isEmptyObject({ a: 1, b: {} })).toEqual(false);
51+
expect(utils.isEmptyObject({ a: 1 })).toEqual(false);
52+
expect(utils.isEmptyObject(null)).toEqual(false);
53+
expect(utils.isEmptyObject(undefined)).toEqual(false);
54+
expect(utils.isEmptyObject(0)).toEqual(false);
55+
expect(utils.isEmptyObject('test')).toEqual(false);
56+
expect(utils.isEmptyObject({})).toEqual(true);
5757
});
5858
});
5959

0 commit comments

Comments
 (0)