useEmittedSounds
Maps emitted domain events to sound effects.
import { useEmittedSounds } from 'filedom/sound';
useEmittedSounds(source, soundMap);
The hook subscribes to each event named in the mapping and plays the mapped sound when it fires. It resubscribes whenever source or soundMap changes identity, so keep both stable.
Parameters
useEmittedSounds<TEvents extends Record<string, unknown>>(
source: EmittedSoundSource<TEvents>,
mapping: EmittedSoundMap<TEvents>,
opts?: { scheme?: SoundScheme<SoundEvent>; backend?: SoundBackend; }
)
source: an emitter with on(eventName, listener), such as an XState store. on may return an unsubscribe function or an object with unsubscribe().
mapping: maps event names to a SoundEvent, or to a function of the event that returns a SoundEvent, { sound, options }, or null to play nothing.
opts: optional scheme and backend, passed to useSound.
const soundMap = { merged: 'merge', won: 'win' } as const;
With this map, a merged event plays merge and a won event plays win.
Returns
Nothing (void).