refactor(updates): only trigger dim updates when dim changed
This commit is contained in:
@@ -52,7 +52,7 @@
|
||||
nodeDragThreshold,
|
||||
selectNodesOnDrag,
|
||||
handleNodeSelection,
|
||||
updateNodeDimensions
|
||||
updateNodeInternals
|
||||
} = store;
|
||||
|
||||
let nodeRef: HTMLDivElement;
|
||||
@@ -97,7 +97,7 @@
|
||||
|
||||
if (doUpdate) {
|
||||
requestAnimationFrame(() =>
|
||||
updateNodeDimensions(
|
||||
updateNodeInternals(
|
||||
new Map([
|
||||
[
|
||||
id,
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
nodesDraggable,
|
||||
nodesConnectable,
|
||||
elementsSelectable,
|
||||
updateNodeDimensions
|
||||
updateNodeInternals
|
||||
} = useStore();
|
||||
|
||||
const resizeObserver: ResizeObserver | null =
|
||||
@@ -29,7 +29,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
updateNodeDimensions(updates);
|
||||
updateNodeInternals(updates);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useStore } from '$lib/store';
|
||||
* @returns function for updating node internals
|
||||
*/
|
||||
export function useUpdateNodeInternals(): UpdateNodeInternals {
|
||||
const { domNode, updateNodeDimensions } = useStore();
|
||||
const { domNode, updateNodeInternals } = useStore();
|
||||
|
||||
// @todo: do we want to add this to system?
|
||||
const updateInternals = (id: string | string[]) => {
|
||||
@@ -27,7 +27,7 @@ export function useUpdateNodeInternals(): UpdateNodeInternals {
|
||||
}
|
||||
});
|
||||
|
||||
requestAnimationFrame(() => updateNodeDimensions(updates));
|
||||
requestAnimationFrame(() => updateNodeInternals(updates));
|
||||
};
|
||||
|
||||
return updateInternals;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user