refactor(react/svelte): use node lookup for perf improvement

This commit is contained in:
moklick
2023-11-13 16:43:57 +01:00
parent 6e1e702cf3
commit a147a20f6e
22 changed files with 127 additions and 78 deletions
@@ -53,9 +53,9 @@ export default (EdgeComponent: ComponentType<EdgeProps>) => {
const [updateHover, setUpdateHover] = useState<boolean>(false);
const [updating, setUpdating] = useState<boolean>(false);
const store = useStoreApi();
const edgePosition = useStore((state) => {
const sourceNode = state.nodes.find((n) => n.id === source);
const targetNode = state.nodes.find((n) => n.id === target);
const edgePosition = useStore(function edgeSelector(state) {
const sourceNode = state.nodesLookup.get(source);
const targetNode = state.nodesLookup.get(target);
if (!sourceNode || !targetNode) {
return null;