Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

EventEmitter

An Event Emitter in TypeScript that supports custom events.

The custom event arguments are supported by intellisense :)

Usage

Instantiate the emitter

import { EventEmitter } from './EventEmitter';

const events = new EventEmitter();

Create and emit custom events

import { MyCustomEvent, SomeOtherEvent } from './MyCustomEvent';

events.emit(new MyCustomEvent({ type: 'click', someValue: 33 }));

events.emit(new SomeOtherEvent(42069));

Listen to custom events

/* Args are type hinted based on the given event :) */
events.on(MyCustomEvent, args => {
  console.log(args.type, args.someValue); // Outputs: 'click', 33
});

events.on(SomeOtherEvent, value => {
  console.log(value); // Outputs: 42069
});

once()

/* Respond to an event only once */
events.once(SomeOtherEvent, value => {
  console.log(value); // Outputs: 42069
});

About

An Event Emitter in TypeScript that supports custom events

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages