Node.js mixin, exposes
on()
,once()
,off()
in an object, allows encapsulating the emitter.
npm install --save @cork-labs/interface-emitter
import { 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
});
npm install -g nodemon http-server
test
- run tests once
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 minor
to publish a minor version)
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.