Skip to content

8128-33550336/typedEventEmitter

Repository files navigation

typedEventEmitter

publish

Package

Language: Japanese

About

This is EventEmiter typed with TypeScript

Install

~/.npmrc

@8128-33550336:registry=https://npm.pkg.github.com

//npm.pkg.github.com/:_authToken=YourTokenHere
$ npm i @8128-33550336/typedeventemitter

Example

Usage as Parent Class

class MyClass extends TypedEventEmitter<{
    foo: [value: string];
    bar: [];
    baz: [value: number];
}> {
    constructor() {
        super();
        this.on('baz', num => {
            this.emit('foo', num + '');
            this.emit('bar');
        });
    }
}

const myClass = new MyClass();

myClass.on('foo', value => {
    console.log('foo', value);
});

myClass.on('bar', () => {
    console.log('bar');
});

myClass.emit('baz', 42);

Simple usage

const myEventEmitter = new TypedEventEmitter();

myEventEmitter.on('baz', num => {
    myEventEmitter.emit('foo', num + '');
    myEventEmitter.emit('bar');
});

myEventEmitter.on('foo', value => {
    console.log('foo', value);
});

myEventEmitter.on('bar', () => {
    console.log('bar');
});

myEventEmitter.emit('baz', 42);

We welcome issues and pull requests.

About

This is EventEmiter typed with TypeScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages