Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tootallnate/node-event-hijack
Hijacks the specified EventEmitter event
https://github.com/tootallnate/node-event-hijack
Last synced: 22 days ago
JSON representation
Hijacks the specified EventEmitter event
- Host: GitHub
- URL: https://github.com/tootallnate/node-event-hijack
- Owner: TooTallNate
- License: mit
- Created: 2013-02-15T23:24:51.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-16T18:50:46.000Z (almost 12 years ago)
- Last Synced: 2024-04-26T21:23:00.495Z (9 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
node-event-hijack
=================
### Hijacks the specified EventEmitter event
[![Build Status](https://travis-ci.org/TooTallNate/node-event-hijack.png?branch=master)](https://travis-ci.org/TooTallNate/node-event-hijack)Hijacks the specified EventEmitter event name.
Installation
------------``` bash
$ npm install event-hijack
```Example
-------``` javascript
var hijack = require('event-hijack');
var EventEmitter = require('events').EventEmitter;// our test subject "emitter" instance
var emitter = new EventEmitter();// you can use the emitter normally
emitter.on('thing', function () {
console.log('got "thing"');
});emitter.emit('thing');
// once you "hijack" the event, subsequent listeners added for that
// event will *not* be added as regular listeners for that event
var emitThing = hijack(emitter, 'thing', function () {
console.log('this is an *original* "thing" event');
});// this will *not* be a "thing" listener. instead, you must
// invoke `emitThing()` for this callback to be invoked
emitter.on('thing', function () {
console.log('this is a *hijacked* event listener');
});// emit a fake "thing" event, the original listener will not be invoked,
// but the hijacked listener *will* be invoked
emitThing();
```