2021-11-15 07:25:19 -05:00
|
|
|
import { useCallback } from 'react'
|
|
|
|
import { useIdeContext } from '../context/ide-context'
|
|
|
|
|
2023-01-09 09:33:43 -05:00
|
|
|
export default function useScopeEventEmitter(
|
|
|
|
eventName: string,
|
|
|
|
broadcast = true
|
|
|
|
) {
|
2021-11-15 07:25:19 -05:00
|
|
|
const { $scope } = useIdeContext()
|
|
|
|
|
|
|
|
return useCallback(
|
2023-01-09 09:33:43 -05:00
|
|
|
(...detail: unknown[]) => {
|
2021-11-15 07:25:19 -05:00
|
|
|
if (broadcast) {
|
2022-11-03 08:43:59 -04:00
|
|
|
$scope.$broadcast(eventName, ...detail)
|
2021-11-15 07:25:19 -05:00
|
|
|
} else {
|
2022-11-03 08:43:59 -04:00
|
|
|
$scope.$emit(eventName, ...detail)
|
2021-11-15 07:25:19 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[$scope, eventName, broadcast]
|
|
|
|
)
|
|
|
|
}
|