import { bindActionCreators , Store , ActionCreator , ActionCreatorsMapObject } from 'redux' ; import { useStore as useStoreRedux , useSelector , useDispatch as reduxUseDispatch , TypedUseSelectorHook , } from 'react-redux' ; import { useMemo } from 'react' ; import { ReactFlowDispatch } from './index' ; import * as actions from './actions' ; import { ReactFlowAction } from './actions' ; import { ReactFlowState } from '../types' ; export const useTypedSelector = useSelector ; export type ActionCreatorSelector < Action > = ( acts : typeof actions ) => ActionCreator < Action > ; export type ActionMapObjectSelector < Action > = ( acts : typeof actions ) => ActionCreatorsMapObject < Action > ; export type ActionSelector < Action > = ( acts : typeof actions ) => ActionCreatorsMapObject < Action > | ActionCreator < Action > ; export function useStoreActions < Action extends ReactFlowAction > ( actionSelector ) ; export function useStoreActions < Action extends ReactFlowAction > ( actionSelector ) ; export function useStoreActions < Action extends ReactFlowAction > ( actionSelector ) { const dispatch = reduxUseDispatch ( ) ; const currAction = actionSelector ( actions ) ; const action = useMemo ( ( ) => { return typeof currAction === 'function' ? bindActionCreators ( currAction , dispatch ) : bindActionCreators ( currAction , dispatch ) ; } , [ dispatch , currAction ] ) ; return action ; } export const useStoreState = useTypedSelector ; export const useStore = ( ) : Store < ReactFlowState , ReactFlowAction > => { const store = useStoreRedux < ReactFlowState , ReactFlowAction > ( ) ; return store ; } ; export const useDispatch = reduxUseDispatch ;