refactor(actions): split up
This commit is contained in:
@@ -9,10 +9,11 @@ import NodeRenderer from '../NodeRenderer';
|
||||
import EdgeRenderer from '../EdgeRenderer';
|
||||
import UserSelection from '../UserSelection';
|
||||
import NodesSelection from '../NodesSelection';
|
||||
import { setNodesSelection } from '../state/actions';
|
||||
import {
|
||||
updateTransform, updateSize, initD3, fitView,
|
||||
zoomIn, zoomOut, setNodesSelection
|
||||
} from '../state/actions';
|
||||
zoomIn, zoomOut
|
||||
} from '../state/view-actions';
|
||||
import { useKeyPress } from '../hooks';
|
||||
|
||||
const d3ZoomInstance = d3Zoom.zoom().scaleExtent([0.5, 2]);
|
||||
|
||||
@@ -1,101 +1,52 @@
|
||||
import {
|
||||
UPDATE_TRANSFORM, UPDATE_SIZE, SET_NODES, SET_EDGES,
|
||||
UPDATE_NODE_DATA, UPDATE_NODE_POS, INIT_D3, FIT_VIEW,
|
||||
SET_NODES, SET_EDGES, UPDATE_NODE_DATA, UPDATE_NODE_POS,
|
||||
UPDATE_SELECTION, SET_SELECTION, SET_NODES_SELECTION,
|
||||
SET_SELECTED_ELEMENTS, REMOVE_NODES, ZOOM_IN, ZOOM_OUT
|
||||
SET_SELECTED_ELEMENTS, REMOVE_NODES,
|
||||
} from './index';
|
||||
|
||||
export const updateTransform = (transform) => {
|
||||
return {
|
||||
type: UPDATE_TRANSFORM,
|
||||
payload: { transform: [transform.x, transform.y, transform.k] }
|
||||
};
|
||||
};
|
||||
export const setNodes = nodes => ({
|
||||
type: SET_NODES,
|
||||
payload: { nodes }
|
||||
});
|
||||
|
||||
export const updateSize = (size) => {
|
||||
return {
|
||||
type: UPDATE_SIZE,
|
||||
payload: size
|
||||
};
|
||||
};
|
||||
export const setEdges = edges => ({
|
||||
type: SET_EDGES,
|
||||
payload: { edges }
|
||||
});
|
||||
|
||||
export const setNodes = (nodes) => {
|
||||
return {
|
||||
type: SET_NODES,
|
||||
payload: { nodes }
|
||||
};
|
||||
};
|
||||
export const updateNodeData = (id, data) => ({
|
||||
type: UPDATE_NODE_DATA,
|
||||
payload: { id, data }
|
||||
});
|
||||
|
||||
export const setEdges = (edges) => {
|
||||
return {
|
||||
type: SET_EDGES,
|
||||
payload: { edges }
|
||||
};
|
||||
};
|
||||
export const updateNodePos = (id, pos) => ({
|
||||
type: UPDATE_NODE_POS,
|
||||
payload: { id, pos }
|
||||
});
|
||||
|
||||
export const updateNodeData = (id, data) => {
|
||||
return {
|
||||
type: UPDATE_NODE_DATA,
|
||||
payload: { id, data }
|
||||
};
|
||||
};
|
||||
export const setSelection = isActive => ({
|
||||
type: SET_SELECTION,
|
||||
payload: { selectionActive: isActive }
|
||||
});
|
||||
|
||||
export const updateNodePos = (id, pos) => {
|
||||
return {
|
||||
type: UPDATE_NODE_POS,
|
||||
payload: { id, pos }
|
||||
};
|
||||
};
|
||||
export const setNodesSelection = ({ isActive, selection }) => ({
|
||||
type: SET_NODES_SELECTION,
|
||||
payload: { nodesSelectionActive: isActive, selection }
|
||||
});
|
||||
|
||||
export const initD3 = ({ zoom, selection }) => {
|
||||
return {
|
||||
type: INIT_D3,
|
||||
payload: { d3Zoom: zoom, d3Selection: selection, d3Initialised: true }
|
||||
};
|
||||
};
|
||||
export const setSelectedElements = elements => ({
|
||||
type: SET_SELECTED_ELEMENTS,
|
||||
payload: {
|
||||
selectedElements: Array.isArray(elements) ? elements : [elements]
|
||||
}
|
||||
});
|
||||
|
||||
export const fitView = ({ padding = 0 } = {}) => {
|
||||
return { type: FIT_VIEW, payload: { padding } };
|
||||
};
|
||||
export const removeNodes = ids => ({
|
||||
type: REMOVE_NODES,
|
||||
payload: { ids: Array.isArray(ids) ? ids : [ids] }
|
||||
});
|
||||
|
||||
export const zoomIn = () => {
|
||||
return { type: ZOOM_IN };
|
||||
};
|
||||
|
||||
export const zoomOut = () => {
|
||||
return { type: ZOOM_OUT };
|
||||
};
|
||||
|
||||
export const setSelection = (isActive) => {
|
||||
return { type: SET_SELECTION, payload: { selectionActive: isActive } };
|
||||
};
|
||||
|
||||
export const setNodesSelection = ({ isActive, selection }) => {
|
||||
return { type: SET_NODES_SELECTION, payload: { nodesSelectionActive: isActive, selection } };
|
||||
};
|
||||
|
||||
export const setSelectedElements = (elements) => {
|
||||
const elementsArray = Array.isArray(elements) ? elements : [elements];
|
||||
|
||||
return {
|
||||
type: SET_SELECTED_ELEMENTS,
|
||||
payload: {
|
||||
selectedElements: elementsArray
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const removeNodes = (ids) => {
|
||||
const idArray = Array.isArray(ids) ? ids : [ids];
|
||||
|
||||
return { type: REMOVE_NODES, payload: { ids: idArray } };
|
||||
};
|
||||
|
||||
export const updateSelection = (selection) => {
|
||||
return {
|
||||
type: UPDATE_SELECTION,
|
||||
payload: {
|
||||
selection
|
||||
}
|
||||
};
|
||||
};
|
||||
export const updateSelection = selection => ({
|
||||
type: UPDATE_SELECTION,
|
||||
payload: { selection }
|
||||
});
|
||||
|
||||
32
src/state/view-actions.js
Normal file
32
src/state/view-actions.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
UPDATE_TRANSFORM, UPDATE_SIZE, INIT_D3,
|
||||
FIT_VIEW, ZOOM_IN, ZOOM_OUT
|
||||
} from './index';
|
||||
|
||||
export const updateTransform = transform => ({
|
||||
type: UPDATE_TRANSFORM,
|
||||
payload: { transform: [transform.x, transform.y, transform.k] }
|
||||
});
|
||||
|
||||
export const updateSize = size => ({
|
||||
type: UPDATE_SIZE,
|
||||
payload: size
|
||||
});
|
||||
|
||||
export const initD3 = ({ zoom, selection }) => ({
|
||||
type: INIT_D3,
|
||||
payload: { d3Zoom: zoom, d3Selection: selection, d3Initialised: true }
|
||||
});
|
||||
|
||||
export const fitView = ({ padding = 0 } = {}) => ({
|
||||
type: FIT_VIEW,
|
||||
payload: { padding }
|
||||
});
|
||||
|
||||
export const zoomIn = () => ({
|
||||
type: ZOOM_IN
|
||||
});
|
||||
|
||||
export const zoomOut = () => ({
|
||||
type: ZOOM_OUT
|
||||
});
|
||||
Reference in New Issue
Block a user