eventemitter-decorator-mixin
v0.0.3
Published
Provides an @event decorator for EventEmitters
Downloads
3
Maintainers
Readme
eventemitter-decorator-mixin
Provides an @event method decorator for EventEmitters
import { Server, Socket } from 'net';
import { EventEmitterDecoratorMixin, event } from 'eventemitter-decorator-mixin';
@EventEmitterDecoratorMixin()
class MyServer extends Server {
@event('connection')
private _onConnection(connection: Socket) {
// ...
}
}
Is equivalent to:
import { Server, Socket } from 'net';
class MyServer extends Server {
constructor(...args: any[]) {
super(...args);
this.on('connection', this._onConnection.bind(this));
}
private _onConnection(connection: Socket) {
// ...
}
}
Features
- Works on any subclass of an EventEmitter
- Is compatible with custom EventEmitter libraries as well as long as they provide an
emit
function with this signature:
public emit(event: string | symbol, ...args: any[]): boolean;
It is important to note that listeners attached using a decorator currently cannot be detached. A pull request enabling support for this feature would be appreciated.
License
This software is licensed under the GNU Lesser General Public License v3.0. Please see the LICENSE
file in the root of the project for the license text.