@cork-labs/mixin-emitter
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Emitter

Node.js mixin, exposes on(), once(), off() in an object, allows encapsulating the emitter.

Getting Started

npm install --save @cork-labs/mixin-emitter
const emitterMixin = require('@cork-labs/mixin-emitter');

class Foobar () {
  constructor() {
    this._emitter = emitterMixin(this);
  }

  bar () {
    this._emitter.emit('baz', 101, 102);
  }
}

const foobar = new Foobar(this);
foobar.on('baz', (arg1, arg2) => {
  console.log(arg1, arg2); // 101, 102
});

API

emitterMixin(instance[, methods])

  • instance - where to expose the methods
  • methods - what methods to expose, defaults to ['on', 'once', 'off']

Develop

# lint and fix
npm run lint

# run test suite
npm test

# lint and test
npm run build

# serve test coverage
npm run coverage

# publish a minor version
node_modules/.bin/npm-bump minor

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.

Links

MIT License

Copyright (c) 2018 Cork Labs

Readme

Keywords

none

Package Sidebar

Install

npm i @cork-labs/mixin-emitter

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

29.2 kB

Total Files

36

Last publish

Collaborators

  • andrezero