import { OutputSelector } from 'reselect' ; import { ChartType } from '../../..' ; import { HeatmapBrushEvent , SettingsSpec } from '../../../../specs/settings' ; import { DragState , GlobalChartState } from '../../../../state/chart_state' ; import { createCustomCachedSelector } from '../../../../state/create_selector' ; import { getLastDragSelector } from '../../../../state/selectors/get_last_drag' ; import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs' ; import { DragCheckProps , hasDragged } from '../../../../utils/events' ; import { HeatmapSpec } from '../../specs' ; import { getPickedCells } from './get_picked_cells' ; import { getSpecOrNull } from './heatmap_spec' ; import { isBrushEndProvided } from './is_brush_available' ; internal export function createOnBrushEndCaller ( ) { let prevProps = null ; let selector = null ; return ( state ) => { if ( selector === null && state . chartType === ChartType . Heatmap ) { if ( ! isBrushEndProvided ( state ) ) { selector = null ; prevProps = null ; return ; } selector = createCustomCachedSelector ( [ getLastDragSelector , getSpecOrNull , getSettingsSpecSelector , getPickedCells ] , ( lastDrag , spec , { onBrushEnd } , pickedCells ) : void => { const nextProps = { lastDrag , onBrushEnd , } ; if ( ! spec || ! onBrushEnd || pickedCells === null ) { return ; } if ( lastDrag !== null && hasDragged ( prevProps , nextProps ) ) { onBrushEnd ( pickedCells ) ; } prevProps = nextProps ; } ) ; } if ( selector ) { selector ( state ) ; } } ; }