Language: Japanese
This is EventEmiter
typed with TypeScript
~/.npmrc
@8128-33550336:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YourTokenHere
$ npm i @8128-33550336/typedeventemitter
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);
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);