import { Selector } from 'react-redux' ; import { ChartType } from '../../..' ; import { SettingsSpec } from '../../../../specs' ; import { GlobalChartState } from '../../../../state/chart_state' ; import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs' ; import { IndexedGeometry } from '../../../../utils/geometry' ; import { getTooltipInfoAndGeometriesSelector , TooltipAndHighlightedGeoms , } from './get_tooltip_values_highlighted_geoms' ; interface Props { settings : SettingsSpec | undefined ; highlightedGeometries : IndexedGeometry [ ] ; } const isOutElement = ( prevProps , nextProps ) : boolean => Boolean ( prevProps && nextProps ?. settings ?. onElementOut && prevProps . highlightedGeometries . length > 0 && nextProps . highlightedGeometries . length === 0 ) ; internal export function createOnElementOutCaller ( ) { let prevProps = null ; let selector = null ; return ( state ) => { if ( selector === null && state . chartType === ChartType . XYAxis ) { selector = createCustomCachedSelector ( [ getTooltipInfoAndGeometriesSelector , getSettingsSpecSelector ] , ( { highlightedGeometries } , settings ) : void => { const nextProps = { settings , highlightedGeometries , } ; if ( isOutElement ( prevProps , nextProps ) && settings . onElementOut ) { settings . onElementOut ( ) ; } prevProps = nextProps ; } ) ; } if ( selector ) { selector ( state ) ; } } ; }