emitter-only
Extend event emitters to allow registering listeners only once.
Last updated 9 years ago by doowb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install emitter-only 
SYNC missed versions from official npm registry.

emitter-only NPM version Build Status

Extend event emitters to allow registering listeners only once.

Install with npm

$ npm i emitter-only --save

Usage

var only = require('emitter-only');

API

only

Only register an event listener one time for the given name/event combo.

Params

  • name {String}: Name to specify this is a unique listener.
  • event {String}: Event name to pass to the emitter on method.
  • fn {Function}: Event listener function to pass to the emitter on method.
  • returns {Object}: Return this for chaining.

Example

Emitter.prototype.only = function () {
  return only.apply(this, arguments);
};

var emitter = new Emitter();
emitter.only('one-time', 'foo', function (msg) {
  console.log('foo 1', msg);
});

emitter.only('one-time', 'foo', function (msg) {
  console.log('foo 2', msg);
});

emitter.emit('foo', 'bar');
//=> 'foo bar'

Related projects

component-emitter: Event emitter | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Brian Woodward

License

Copyright © 2015 Brian Woodward Released under the MIT license.


This file was generated by verb-cli on September 23, 2015.

Current Tags

  • 0.1.0                                ...           latest (9 years ago)

1 Versions

  • 0.1.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE