refactor(general): fit view in store to prevent flickering, rename onLoad => onPaneReady

This commit is contained in:
moklick
2021-12-09 07:24:45 +01:00
parent 3a52efbb1f
commit 88582a86cc
17 changed files with 96 additions and 100 deletions
+8
View File
@@ -36,6 +36,7 @@ interface StoreUpdaterProps {
snapToGrid?: boolean;
snapGrid?: SnapGrid;
translateExtent?: CoordinateExtent;
fitViewOnInit: boolean;
}
const selector = (s: ReactFlowState) => ({
@@ -58,6 +59,7 @@ const selector = (s: ReactFlowState) => ({
setOnNodesChange: s.setOnNodesChange,
setOnEdgesChange: s.setOnEdgesChange,
reset: s.reset,
setFitViewOnInit: s.setFitViewOnInit,
});
const StoreUpdater = ({
@@ -79,6 +81,7 @@ const StoreUpdater = ({
snapGrid,
snapToGrid,
translateExtent,
fitViewOnInit,
}: StoreUpdaterProps) => {
const {
setNodes,
@@ -100,6 +103,7 @@ const StoreUpdater = ({
setOnEdgesChange,
setConnectionMode,
reset,
setFitViewOnInit,
} = useStore(selector, shallow);
useEffect(() => {
@@ -212,6 +216,10 @@ const StoreUpdater = ({
}
}, [onEdgesChange]);
useEffect(() => {
setFitViewOnInit(fitViewOnInit);
}, [fitViewOnInit]);
return null;
};