mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
efcc15d5b5
GitOrigin-RevId: bf756a415dbf1e4b5bbd9f580700bdc799c6b1d6
22 lines
513 B
JavaScript
22 lines
513 B
JavaScript
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(
|
|
detail => {
|
|
if (broadcast) {
|
|
$scope.$broadcast(eventName, detail)
|
|
} else {
|
|
$scope.$emit(eventName, detail)
|
|
}
|
|
},
|
|
[$scope, eventName, broadcast]
|
|
)
|
|
}
|