mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-27 12:08:38 +00:00
Use useTypedEventEmitterState for broadcasts (#9947)
This commit is contained in:
@@ -63,6 +63,9 @@ export function useEventEmitter(emitter: EventEmitter | undefined, eventName: st
|
||||
|
||||
type Mapper<T> = (...args: any[]) => T;
|
||||
|
||||
/**
|
||||
* {@link useEventEmitterState}
|
||||
*/
|
||||
export function useTypedEventEmitterState<T, Events extends string, Arguments extends ListenerMap<Events>>(
|
||||
emitter: TypedEventEmitter<Events, Arguments>,
|
||||
eventName: Events,
|
||||
@@ -71,6 +74,16 @@ export function useTypedEventEmitterState<T, Events extends string, Arguments ex
|
||||
return useEventEmitterState<T>(emitter, eventName, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a state, that can be updated by events.
|
||||
*
|
||||
* @param emitter The emitter sending the event
|
||||
* @param eventName Event name to listen for
|
||||
* @param fn The callback function, that should return the state value.
|
||||
* It should have the signature of the event callback, except that all parameters are optional.
|
||||
* If the params are not set, a default value for the state should be returned.
|
||||
* @returns State
|
||||
*/
|
||||
export function useEventEmitterState<T>(
|
||||
emitter: EventEmitter | undefined,
|
||||
eventName: string | symbol,
|
||||
|
||||
Reference in New Issue
Block a user