import { debounce } from 'ts-debounce' ; import { ChartType } from '../../chart_types' ; import { SpecType , DEFAULT_SETTINGS_SPEC } from '../../specs/constants' ; import { SettingsSpec } from '../../specs/settings' ; import { GlobalChartState } from '../chart_state' ; import { createCustomCachedSelector } from '../create_selector' ; import { getSpecsFromStore } from '../utils' ; const DEFAULT_POINTER_UPDATE_DEBOUNCE = 16 ; internal export const getSpecs = ( state ) => state . specs ; internal export const getSettingsSpecSelector = createCustomCachedSelector ( [ getSpecs ] , ( specs ) : SettingsSpec => { const settingsSpecs = getSpecsFromStore < SettingsSpec > ( specs , ChartType . Global , SpecType . Settings ) ; if ( settingsSpecs . length === 1 ) { return handleListenerDebouncing ( settingsSpecs [ 0 ] ) ; } return DEFAULT_SETTINGS_SPEC ; } ) ; function handleListenerDebouncing ( settings ) { const delay = settings . pointerUpdateDebounce ?? DEFAULT_POINTER_UPDATE_DEBOUNCE ; if ( settings . onPointerUpdate ) settings . onPointerUpdate = debounce ( settings . onPointerUpdate , delay ) ; return settings ; }