Skip to content
generated from khrj/blueprint

Strictly typed EventTarget for Deno and the Browser

License

Notifications You must be signed in to change notification settings

khrj/typed-event-target

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typed_event_target illustration

Typed Event Target

Strictly typed EventTarget for Deno and the Browser

build status language code size issues license version

View on deno.land




Usage

import { TypedCustomEvent, TypedEventTarget } from 'https://deno.land/x/[email protected]/mod.ts'

type Events = {
    Hi: string
    Hello: boolean
}

const emitter = new TypedEventTarget<Events>()

emitter.addEventListener("Hi", (value) => {
    console.log(value.detail) // "Hello"
})

emitter.dispatchEvent(new TypedCustomEvent("Hi", { detail: "Hello" }))

API

Same as non-strict EventTarget, however a parameter must be passed to TypedCustomEvent.

Supporters

Stargazers repo roster for @khrj/typed-event-target

Forkers repo roster for @khrj/typed-event-target

Related