1.0.3 • Published 6 months ago
@hydroperx/event v1.0.3
Event
Easily define event types for an EventTarget
. Credits to this article.
Getting started
The following program defines play
and stop
events.
import { TypedEventTarget } from "@hydroperx/event";
class MediaPlayer extends (EventTarget as TypedEventTarget<{
play: CustomEvent<MediaPlayerEvent>;
stop: CustomEvent<MediaPlayerEvent>;
}>) {}
Note that event types must implement the
Event
interface, thus in the previous programCustomEvent
is used; if there was no data, it could have just beenEvent
itself.