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

Refactor/clean link component #139

Merged
merged 2 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/components/graph/graph.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ function buildLinkProps(link, nodes, links, config, linkCallbacks, highlightedNo
d,
source,
target,
x1,
y1,
x2,
y2,
strokeWidth,
stroke,
mouseCursor: config.link.mouseCursor,
Expand Down Expand Up @@ -434,7 +430,7 @@ function checkForGraphElementsChanges(nextProps, currentState) {
function checkForGraphConfigChanges(nextProps, currentState) {
const newConfig = nextProps.config || {};
const configUpdated =
newConfig && !utils.isObjectEmpty(newConfig) && !utils.isDeepEqual(newConfig, currentState.config);
newConfig && !utils.isEmptyObject(newConfig) && !utils.isDeepEqual(newConfig, currentState.config);
const d3ConfigUpdated = newConfig && newConfig.d3 && !utils.isDeepEqual(newConfig.d3, currentState.config.d3);

return { configUpdated, d3ConfigUpdated };
Expand Down
4 changes: 0 additions & 4 deletions src/components/link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import React from 'react';
* d="M1..."
* source='idSourceNode'
* target='idTargetNode'
* x1=22
* y1=22
* x2=22
* y2=22
* markerId='marker-small'
* strokeWidth=1.5
* stroke='green'
Expand Down
12 changes: 6 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const MAX_DEPTH = 20;
* @memberof utils
*/
function _isPropertyNestedObject(o, k) {
return o.hasOwnProperty(k) && typeof o[k] === 'object' && o[k] !== null && !isObjectEmpty(o[k]);
return o.hasOwnProperty(k) && typeof o[k] === 'object' && o[k] !== null && !isEmptyObject(o[k]);
}

/**
Expand All @@ -35,7 +35,7 @@ function isDeepEqual(o1, o2, _depth = 0) {
return true;
}

if ((isObjectEmpty(o1) && !isObjectEmpty(o2)) || (!isObjectEmpty(o1) && isObjectEmpty(o2))) {
if ((isEmptyObject(o1) && !isEmptyObject(o2)) || (!isEmptyObject(o1) && isEmptyObject(o2))) {
return false;
}

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

diffs.push(r);

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

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

if (Object.keys(o1 || {}).length === 0) {
return o2 && !isObjectEmpty(o2) ? o2 : {};
return o2 && !isEmptyObject(o2) ? o2 : {};
}

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

export default {
isDeepEqual,
isObjectEmpty,
isEmptyObject,
merge,
pick,
antiPick,
Expand Down
2 changes: 1 addition & 1 deletion test/component/graph/graph.helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
describe('Graph Helper', () => {
beforeAll(() => {
utils.isDeepEqual = jest.fn();
utils.isObjectEmpty = jest.fn();
utils.isEmptyObject = jest.fn();
utils.merge = jest.fn();
utils.throwErr = jest.fn();
jest.spyOn(linkHelper, 'buildLinkPathDefinition');
Expand Down
16 changes: 8 additions & 8 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ describe('Utils', () => {
});
});

describe('#isObjectEmpty', () => {
describe('#isEmptyObject', () => {
test('should properly check whether the object is empty or not', () => {
expect(utils.isObjectEmpty({ a: 1, b: {} })).toEqual(false);
expect(utils.isObjectEmpty({ a: 1 })).toEqual(false);
expect(utils.isObjectEmpty(null)).toEqual(false);
expect(utils.isObjectEmpty(undefined)).toEqual(false);
expect(utils.isObjectEmpty(0)).toEqual(false);
expect(utils.isObjectEmpty('test')).toEqual(false);
expect(utils.isObjectEmpty({})).toEqual(true);
expect(utils.isEmptyObject({ a: 1, b: {} })).toEqual(false);
expect(utils.isEmptyObject({ a: 1 })).toEqual(false);
expect(utils.isEmptyObject(null)).toEqual(false);
expect(utils.isEmptyObject(undefined)).toEqual(false);
expect(utils.isEmptyObject(0)).toEqual(false);
expect(utils.isEmptyObject('test')).toEqual(false);
expect(utils.isEmptyObject({})).toEqual(true);
});
});

Expand Down