0.3.1 • Published 7 years ago
@cork-labs/interface-emitter v0.3.1
Emitter
Node.js mixin, exposes
on(),once(),off()in an object, allows encapsulating the emitter.
Getting Started
npm install --save @cork-labs/interface-emitterimport { EventEmitter, EventName, IEmitter, ListenerCallback } from '@cork-labs/interface-emitter';
export class Foo implements IEmitter {
private emitter: EventEmitter;
constructor () {
this.emitter = new EventEmitter();
}
public bar (...args: number[]) {
this.emitter.emit('bar', 33, 42);
}
public on (event: EventName, listener: ListenerCallback): void {
this.emitter.on(event, listener);
}
public off (event: EventName, listener: ListenerCallback): void {
this.emitter.off(event, listener);
}
public once (event: EventName, listener: ListenerCallback): void {
this.emitter.once(event, listener);
}
}
const foo = new Foo();
foo.on('bar', () => {
console.log(arg1, arg2); // 33, 42
});Development
Install dependencies
npm install -g nodemon http-serverCode, test, publish
VSCode launchers:
test- run tests once
NPM scripts:
npm run dev- run tests (restarts when files saved)npm run lint- lintnpm run lint-fix- lint and fixnpm test- run all test suites and produce code coverage reportsnpm run test-u- run unit testsnpm run test-i- run integration testsnpm run coverage- serve test coverage reportsnpm run clean- delete all build artifactsnpm run build- lint and testnpm run pub- publish a patch version (usenpm-bump minorto publish a minor version)
Contributing
We'd love for you to contribute to our source code and to make it even better than it is today!
Check CONTRIBUTING before submitting issues and PRs.