From acd6b76b14dbff0319463539029ac5cf35c5f037 Mon Sep 17 00:00:00 2001 From: moklick Date: Sun, 14 Feb 2021 14:52:03 +0100 Subject: [PATCH] refactor(examples): clean up node type change example --- example/src/NodeTypeChange/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/example/src/NodeTypeChange/index.js b/example/src/NodeTypeChange/index.js index b414392b..c5dce1ea 100644 --- a/example/src/NodeTypeChange/index.js +++ b/example/src/NodeTypeChange/index.js @@ -1,6 +1,6 @@ import React, { useState } from 'react'; -import ReactFlow, { addEdge } from 'react-flow-renderer'; +import ReactFlow, { addEdge, isEdge } from 'react-flow-renderer'; const onLoad = (reactFlowInstance) => reactFlowInstance.fitView(); @@ -23,19 +23,20 @@ const initialElements = [ { id: 'e1-2', source: '1', type: 'smoothstep', target: '2', animated: true }, ]; -const HorizontalFlow = () => { +const NodeTypeChangeFlow = () => { const [elements, setElements] = useState(initialElements); const onConnect = (params) => setElements((els) => addEdge(params, els)); const changeType = () => { setElements((elms) => elms.map((el) => { - if (el.type === 'input') { + if (isEdge(el) || el.type === 'input') { return el; } - el.type = el.type === 'default' ? 'output' : 'default'; - - return { ...el }; + return { + ...el, + type: el.type === 'default' ? 'output' : 'default', + }; }) ); }; @@ -49,4 +50,4 @@ const HorizontalFlow = () => { ); }; -export default HorizontalFlow; +export default NodeTypeChangeFlow;