import { useCreateEventBus } from '@/widgets/events/use-create-event-bus' ; import { useTupleEventBus } from '@/widgets/tuple-workbench/tuple-event-bus' ; import { TupleEventTypes , TupleState } from '@/widgets/tuple-workbench/tuple-event-bus-types' ; import React , { createContext , ReactNode , useContext } from 'react' ; import { DataSourceEventBus } from './data-source-event-bus-types' ; const Context = createContext < DataSourceEventBus > ( { } as DataSourceEventBus ) ; Context . displayName = 'DataSourceEventBus' ; export const DataSourceEventBusProvider = ( props ) => { const { children } = props ; const { fire } = useTupleEventBus ( ) ; const bus = useCreateEventBus < DataSourceEventBus > ( 'data source' , { beforeFire : ( ) => fire ( TupleEventTypes . CHANGE_TUPLE_STATE , TupleState . CHANGED ) } ) ; return < Context . Provider value = { bus } > { children } < /Context.Provider>; } ; export const useDataSourceEventBus = ( ) => useContext ( Context ) ;