import { useEffect } from 'react' ; import { useDataQualityCacheEventBus } from './cache-event-bus' ; import { DataQualityCacheEventTypes } from './cache-event-bus-types' ; import { DQCCacheData } from './types' ; /**
 * make sure options will not change, this must be executed only once
 */ export const useDataQualityCacheData = ( options ) => { const { onDataRetrieved } = options ; const { fire } = useDataQualityCacheEventBus ( ) ; useEffect ( ( ) => { const askData = ( ) => { fire ( DataQualityCacheEventTypes . ASK_DATA , ( data ? ) => { onDataRetrieved ( data ) ; } ) ; } ; const askDataLoaded = ( askData ) => { fire ( DataQualityCacheEventTypes . ASK_DATA_LOADED , ( loaded ) => { if ( loaded ) { askData ( ) ; } else { setTimeout ( ( ) => askDataLoaded ( askData ) , 100 ) ; } } ) ; } ; askDataLoaded ( askData ) ; } , [ fire , onDataRetrieved ] ) ; } ;