refactor(state): use easy-peasy

This commit is contained in:
moklick
2019-08-20 17:48:04 +02:00
parent 4a79beac43
commit feca64048a
24 changed files with 434 additions and 435 deletions
+9 -5
View File
@@ -1,22 +1,26 @@
import React, { useRef, useContext, useEffect } from 'react';
import React, { useRef, useEffect } from 'react';
import { useStoreState } from 'easy-peasy';
import classnames from 'classnames';
import { isFunction } from '../../utils'
import { getNodesInside } from '../../graph-utils';
import { GraphContext } from '../../GraphContext';
const baseStyle = {
position: 'absolute',
zIndex: 5,
bottom: 10,
right: 10,
width: 200,
width: 200
};
export default ({ style = {}, className, bgColor = '#f8f8f8', nodeColor = '#ddd' }) => {
const canvasNode = useRef(null);
const { state } = useContext(GraphContext);
const mapClasses = classnames('react-graph__minimap', className);
const state = useStoreState(s => ({
width: s.width,
height: s.height,
nodes: s.nodes,
transform: s.transform,
})); const mapClasses = classnames('react-graph__minimap', className);
const nodePositions = state.nodes.map(n => n.__rg.position);
const width = style.width || baseStyle.width;
const height = (state.height / (state.width || 1)) * width;