overleaf/services/web/frontend/js/shared/hooks/use-scope-event-emitter.js
Mathias Jakobsen a54b633726 Merge pull request #10111 from overleaf/mj-lezer-file-outline
[web] Parser backed file outline

GitOrigin-RevId: 0825f4887ba4dae24a14dd1880d07b791d0b4cd9
2022-11-04 09:04:33 +00:00

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]
)
}