refactor(zoom): move zoom methods into own hook, detatch from store

This commit is contained in:
Christopher Möller
2020-11-09 17:23:59 +01:00
parent 803a4aea57
commit cf38388f14
8 changed files with 139 additions and 152 deletions
+5 -6
View File
@@ -22,6 +22,7 @@ import {
OnConnectEndFunc,
TranslateExtent,
} from '../../types';
import useZoomPanHelper from '../../hooks/useZoomPanHelper';
export interface GraphViewProps {
elements: Elements;
@@ -145,10 +146,8 @@ const GraphView = ({
const setMinZoom = useStoreActions((actions) => actions.setMinZoom);
const setMaxZoom = useStoreActions((actions) => actions.setMaxZoom);
const setTranslateExtent = useStoreActions((actions) => actions.setTranslateExtent);
const fitView = useStoreActions((actions) => actions.fitView);
const zoom = useStoreActions((actions) => actions.zoom);
const zoomTo = useStoreActions((actions) => actions.zoomTo);
const currentStore = useStore();
const { zoomIn, zoomOut, zoomTo, fitView } = useZoomPanHelper();
useElementUpdater(elements);
@@ -157,9 +156,9 @@ const GraphView = ({
if (onLoad) {
onLoad({
fitView: (params = { padding: 0.1 }) => fitView(params),
zoomIn: () => zoom(0.2),
zoomOut: () => zoom(-0.2),
zoomTo: (zoomLevel) => zoomTo(zoomLevel),
zoomIn,
zoomOut,
zoomTo,
project: onLoadProject(currentStore),
getElements: onLoadGetElements(currentStore),
setTransform: (transform: FlowTransform) =>