Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/floatdrop/after-event

Execute function after event is emitted and on any proceeding call
https://github.com/floatdrop/after-event

Last synced: 22 days ago
JSON representation

Execute function after event is emitted and on any proceeding call

Awesome Lists containing this project

README

        

# after-event [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

## Usage

```js

var after = require('after-event');
var events = require('events');
var ee = new events.EventEmitter();

after(ee, 'bang', function (data) { console.log(data); });

ee.emit('bang', 'emitted bang'); // Logs `emitted bang` and saves arguments to proceeding calls

after(ee, 'bang', function (data) { console.log('other' + data); }); // Logs `other emitted bang` without emit called

ee.emit('bang', 'emitted bang 2'); // Stores new value
```

## API

### after(eventemitter, event, cb)

Attaches event listener to `eventemitter` if such event was not emitted yet. Calls callback otherwise.

## License

MIT (c) 2014 Vsevolod Strukchinsky

[npm-url]: https://npmjs.org/package/after-event
[npm-image]: https://badge.fury.io/js/after-event.png

[travis-url]: http://travis-ci.org/floatdrop/after-event
[travis-image]: https://travis-ci.org/floatdrop/after-event.png?branch=master