2021-11-15 07:25:19 -05:00
|
|
|
import { useCallback } from 'react'
|
|
|
|
import { useIdeContext } from '../context/ide-context'
|
2023-10-24 10:57:17 -04:00
|
|
|
import { ScopeEventName } from '../../../../types/ide/scope-event-emitter'
|
2021-11-15 07:25:19 -05:00
|
|
|
|
2023-01-09 09:33:43 -05:00
|
|
|
export default function useScopeEventEmitter(
|
2023-10-24 10:57:17 -04:00
|
|
|
eventName: ScopeEventName,
|
2023-01-09 09:33:43 -05:00
|
|
|
broadcast = true
|
|
|
|
) {
|
2023-10-24 10:57:17 -04:00
|
|
|
const { scopeEventEmitter } = useIdeContext()
|
2021-11-15 07:25:19 -05:00
|
|
|
|
|
|
|
return useCallback(
|
2023-01-09 09:33:43 -05:00
|
|
|
(...detail: unknown[]) => {
|
2023-10-24 10:57:17 -04:00
|
|
|
scopeEventEmitter.emit(eventName, broadcast, ...detail)
|
2021-11-15 07:25:19 -05:00
|
|
|
},
|
2023-10-24 10:57:17 -04:00
|
|
|
[scopeEventEmitter, eventName, broadcast]
|
2021-11-15 07:25:19 -05:00
|
|
|
)
|
|
|
|
}
|