0.0.3 • Published 6 years ago

eventemitter-decorator-mixin v0.0.3

Weekly downloads
1
License
LGPL-3.0
Repository
github
Last release
6 years ago

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.

0.0.3

6 years ago

0.0.2-a

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago