mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 14:49:01 +02:00
dc35c3a6e7
[web] Parser backed file outline GitOrigin-RevId: 0825f4887ba4dae24a14dd1880d07b791d0b4cd9
23 lines
524 B
JavaScript
23 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]
|
|
)
|
|
}
|