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