A super simple and lightweight event emitter.
Repository | Package | Releases | Discussions
npm i @hypernym/emitter
- TypeScript friendly
- Fully tree-shakeable
- No dependencies
import { createEmitter } from '@hypernym/emitter'
const emitter = createEmitter()
emitter.on('event-id', (e) => console.log(e.x, e.y))
emitter.emit('event-id', { x: 0, y: 0 })
import { createEmitter, type Emitter } from '@hypernym/emitter'
type Events = {
'event-id': { x: number; y: number }
// ...
}
const emitter: Emitter<Events> = createEmitter<Events>()
emitter.on('event-id', (e) => console.log(e.x, e.y))
emitter.emit('event-id', { x: 0, y: 0 })
Registers a specific event.
emitter.on(id: string, callback: (event: any) => void)
Emits a specific event.
emitter.emit(id: string, event: any)
Main events map.
Stores all registered events.
emitter.events
Checks if a specific event by id
exists in the map.
emitter.events.has(id: string)
Gets a specific event by id
from the map.
emitter.events.get(id: string)
Deletes a specific event by id
from the map.
emitter.events.delete(id: string)
Removes all events from the map.
emitter.events.clear()
Feel free to use the official discussions for any additional questions.
Developed in 🇭🇷 Croatia
Released under the MIT license.
© Hypernym Studio