mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
537673cdf6
IDE scope store and emitter with fixed PDF URLs GitOrigin-RevId: 9d33bad8a006bb55714878332f78932538dd8921
26 lines
910 B
TypeScript
26 lines
910 B
TypeScript
import {
|
|
ScopeEventEmitter,
|
|
ScopeEventName,
|
|
} from '../../../../../types/ide/scope-event-emitter'
|
|
import EventEmitter from 'events'
|
|
|
|
export class ReactScopeEventEmitter implements ScopeEventEmitter {
|
|
// eslint-disable-next-line no-useless-constructor
|
|
constructor(private readonly eventEmitter: EventEmitter) {}
|
|
|
|
emit(eventName: ScopeEventName, broadcast: boolean, ...detail: unknown[]) {
|
|
this.eventEmitter.emit(eventName, ...detail)
|
|
}
|
|
|
|
on(eventName: ScopeEventName, listener: (...args: unknown[]) => void) {
|
|
// A listener attached via useScopeEventListener expects an event as the
|
|
// first parameter. We don't have one, so just provide an empty object
|
|
const wrappedListener = (...detail: unknown[]) => {
|
|
listener({}, ...detail)
|
|
}
|
|
this.eventEmitter.on(eventName, wrappedListener)
|
|
return () => {
|
|
this.eventEmitter.off(eventName, wrappedListener)
|
|
}
|
|
}
|
|
}
|