overleaf/services/web/frontend/js/shared/hooks/use-scope-event-emitter.ts
Jakob Ackermann 74c6085c55 Merge pull request #15412 from overleaf/revert-15280-td-scope-store-and-emitter
Revert "IDE scope store and emitter"

GitOrigin-RevId: bb764c66830e5e30806609b2834f918cf7784dd7
2023-10-25 08:04:17 +00:00

20 lines
459 B
TypeScript

import { useCallback } from 'react'
import { useIdeContext } from '../context/ide-context'
export default function useScopeEventEmitter(
eventName: string,
broadcast = true
) {
const { $scope } = useIdeContext()
return useCallback(
(...detail: unknown[]) => {
if (broadcast) {
$scope.$broadcast(eventName, ...detail)
} else {
$scope.$emit(eventName, ...detail)
}
},
[$scope, eventName, broadcast]
)
}