2021-11-15 07:25:19 -05:00
|
|
|
import { useCallback } from 'react'
|
|
|
|
import { useIdeContext } from '../context/ide-context'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} eventName
|
|
|
|
* @param {boolean} [broadcast]
|
|
|
|
* @returns function
|
|
|
|
*/
|
|
|
|
export default function useScopeEventEmitter(eventName, broadcast = true) {
|
|
|
|
const { $scope } = useIdeContext()
|
|
|
|
|
|
|
|
return useCallback(
|
2022-11-03 08:43:59 -04:00
|
|
|
(...detail) => {
|
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]
|
|
|
|
)
|
|
|
|
}
|