import createCachedSelector , { ICacheObject , Options } from 're-reselect' ; import type { createSelector } from 'reselect' ; import { GlobalChartState } from './chart_state' ; /**
 * Custom object cache
 * see https://github.com/toomuchdesign/re-reselect/tree/master/src/cache#write-your-custom-cache-object
 */ class CustomMapCache implements ICacheObject { private cache : any = { } ; set ( key , selectorFn ) { this . cache [ key ] = selectorFn ; } get ( key ) { return this . cache [ key ] ; } remove ( key ) { delete this . cache [ key ] ; } clear ( ) { this . cache = { } ; } isEmpty ( ) { return Object . keys ( this . cache ) . length === 0 ; } isValidCacheKey ( key ) { return typeof key === 'string' ; } } class GlobalSelectorCache { private selectorCaches : CustomMapCache [ ] = [ ] ; static keySelector ( { chartId } ) { return chartId ; } getNewOptions ( ) { return { keySelector : GlobalSelectorCache . keySelector , cacheObject : this . getCacheObject ( ) , } ; } removeKeyFromAll ( key ) { this . selectorCaches . forEach ( ( cache ) => { cache . remove ( key ) ; } ) ; } private getCacheObject ( ) { const cache = new CustomMapCache ( ) ; this . selectorCaches . push ( cache ) ; return cache ; } } internal export const globalSelectorCache = new GlobalSelectorCache ( ) ; internal export const createCustomCachedSelector = ( ... args ) => { return createCachedSelector ( ... args ) ( globalSelectorCache . getNewOptions ( ) ) ; } ;