mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
a54b633726
[web] Parser backed file outline GitOrigin-RevId: 0825f4887ba4dae24a14dd1880d07b791d0b4cd9
22 lines
524 B
JavaScript
22 lines
524 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]
|
|
)
|
|
}
|