refactor(renderer): dont rerender nodes when selcting element

This commit is contained in:
moklick
2019-08-05 14:19:49 +02:00
parent bcf5ea2ccd
commit e148e27893
7 changed files with 42 additions and 43 deletions
+1 -3
View File
@@ -3,7 +3,6 @@ import ReactDraggable from 'react-draggable';
import cx from 'classnames';
import { updateNodeData, updateNodePos, setSelectedElements } from '../../state/actions';
import { isNode } from '../../graph-utils';
import { Provider } from '../NodeIdContext';
const isInput = e => ['INPUT', 'SELECT', 'TEXTAREA'].includes(e.target.nodeName);
@@ -88,13 +87,12 @@ export default NodeComponent => {
const [offset, setOffset] = useState({ x: 0, y: 0 });
const [isDragging, setDragging] = useState(false);
const {
id, type, data, transform, xPos, yPos, selectedElements,
id, type, data, transform, xPos, yPos, selected,
dispatch, getNodeById, onClick, onNodeDragStop
} = props;
const position = { x: xPos, y: yPos };
const [ x, y, k ] = transform;
const selected = selectedElements.filter(isNode).map(e => e.id).includes(id);
const nodeClasses = cx('react-graph__node', { selected });
const nodeStyle = { zIndex: selected ? 10 : 3, transform: `translate(${xPos}px,${yPos}px)` };
+6 -1
View File
@@ -1,6 +1,7 @@
import React, { memo, useContext } from 'react';
import { GraphContext } from '../GraphContext';
import { isNode } from '../graph-utils';
function renderNode(d, props, graphContext) {
const nodeType = d.type || 'default';
@@ -10,6 +11,10 @@ function renderNode(d, props, graphContext) {
}
const NodeComponent = props.nodeTypes[nodeType] || props.nodeTypes.default;
const selected = graphContext.state.selectedElements
.filter(isNode)
.map(e => e.id)
.includes(d.id);
return (
<NodeComponent
@@ -24,7 +29,7 @@ function renderNode(d, props, graphContext) {
dispatch={graphContext.dispatch}
transform={graphContext.state.transform}
getNodeById={graphContext.getNodeById}
selectedElements={graphContext.state.selectedElements}
selected={selected}
style={d.style}
/>
);