refactor(updates): only trigger dim updates when dim changed

This commit is contained in:
moklick
2024-04-11 12:31:14 +02:00
parent 63aa0dd713
commit 4fa3a87241
14 changed files with 57 additions and 53 deletions
+6 -6
View File
@@ -5,10 +5,10 @@ import {
fitView as fitViewUtil,
getElementsToRemove,
panBy as panBySystem,
updateNodeDimensions as updateNodeDimensionsSystem,
updateNodeInternals as updateNodeInternalsSystem,
addEdge as addEdgeUtil,
type UpdateNodePositions,
type NodeDimensionUpdate,
type InternalNodeUpdate,
type ViewportHelperFunctionOptions,
type Connection,
type XYPosition,
@@ -78,16 +78,16 @@ export function createStore({
store.nodes.update((nds) => nds);
};
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
function updateNodeInternals(updates: Map<string, InternalNodeUpdate>) {
const nodeLookup = get(store.nodeLookup);
const changes = updateNodeDimensionsSystem(
const { changes, updatedInternals } = updateNodeInternalsSystem(
updates,
nodeLookup,
get(store.domNode),
get(store.nodeOrigin)
);
if (!changes) {
if (!updatedInternals) {
return;
}
@@ -400,7 +400,7 @@ export function createStore({
setEdgeTypes,
addEdge,
updateNodePositions,
updateNodeDimensions,
updateNodeInternals,
zoomIn,
zoomOut,
fitView: (options?: FitViewOptions) => fitView(options),
+2 -2
View File
@@ -1,6 +1,6 @@
import type { Writable } from 'svelte/store';
import type {
NodeDimensionUpdate,
InternalNodeUpdate,
XYPosition,
ViewportHelperFunctionOptions,
Connection,
@@ -27,7 +27,7 @@ export type SvelteFlowStoreActions = {
setTranslateExtent: (extent: CoordinateExtent) => void;
fitView: (options?: FitViewOptions) => boolean;
updateNodePositions: UpdateNodePositions;
updateNodeDimensions: (updates: Map<string, NodeDimensionUpdate>) => void;
updateNodeInternals: (updates: Map<string, InternalNodeUpdate>) => void;
unselectNodesAndEdges: (params?: { nodes?: Node[]; edges?: Edge[] }) => void;
addSelectedNodes: (ids: string[]) => void;
addSelectedEdges: (ids: string[]) => void;