refactor(updates): only trigger dim updates when dim changed
This commit is contained in:
@@ -2,12 +2,12 @@ import { useEffect, useMemo, useRef } from 'react';
|
||||
|
||||
import { ReactFlowState } from '../../types';
|
||||
import { useStore } from '../../hooks/useStore';
|
||||
import { NodeDimensionUpdate } from '@xyflow/system';
|
||||
import { InternalNodeUpdate } from '@xyflow/system';
|
||||
|
||||
const selector = (s: ReactFlowState) => s.updateNodeDimensions;
|
||||
const selector = (s: ReactFlowState) => s.updateNodeInternals;
|
||||
|
||||
export function useResizeObserver() {
|
||||
const updateNodeDimensions = useStore(selector);
|
||||
const updateNodeInternals = useStore(selector);
|
||||
const resizeObserverRef = useRef<ResizeObserver>();
|
||||
|
||||
const resizeObserver = useMemo(() => {
|
||||
@@ -16,7 +16,7 @@ export function useResizeObserver() {
|
||||
}
|
||||
|
||||
const observer = new ResizeObserver((entries: ResizeObserverEntry[]) => {
|
||||
const updates = new Map<string, NodeDimensionUpdate>();
|
||||
const updates = new Map<string, InternalNodeUpdate>();
|
||||
|
||||
entries.forEach((entry: ResizeObserverEntry) => {
|
||||
const id = entry.target.getAttribute('data-id') as string;
|
||||
@@ -26,7 +26,7 @@ export function useResizeObserver() {
|
||||
});
|
||||
});
|
||||
|
||||
updateNodeDimensions(updates);
|
||||
updateNodeInternals(updates);
|
||||
});
|
||||
|
||||
resizeObserverRef.current = observer;
|
||||
|
||||
Reference in New Issue
Block a user