Skip to content

Commit

Permalink
refactor(utils): throw error when elements have no id
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 7, 2019
1 parent 859ac67 commit c6bc8a5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/utils/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export const removeElements = (elements, elementsToRemove) => {
});
};

const getEdgeId = (e) => `react-flow__edge-${e.source}-${e.target}`;

const pointToRendererPoint = ({ x, y }, transform) => {
const rendererX = (x - transform[0]) * (1 / [transform[2]]);
const rendererY = (y - transform[1]) * (1 / [transform[2]]);
Expand All @@ -39,11 +37,15 @@ const pointToRendererPoint = ({ x, y }, transform) => {
};

export const parseElement = (e, transform) => {
if (!e.id) {
throw new Error('All elements (nodes and edges) need to have an id.',)
}

if (isEdge(e)) {
return {
...e,
type: e.type || 'default',
id: e.id ? e.id.toString() : getEdgeId(e)
id: e.id.toString(),
type: e.type || 'default'
};
}

Expand Down

0 comments on commit c6bc8a5

Please sign in to comment.