modify-event
Advanced tools
Weekly downloads
Readme
Modify the value of the specific object's event
const {EventEmitter} = require('events');
const modifyEvent = require('modify-event');
const emitter = new EventEmitter();
modifyEvent(emitter, 'foo', val => val * 2);
emitter.on('foo', data => {
data; //=> 2
});
emitter.emit('foo', 1);
npm install modify-event
const modifyEvent = require('modify-event');
eventEmitter: EventEmitter
eventName: string
symbol
(event name)
modifier: Function
Return: EventEmitter
(a reference to the first argument)
It changes the first argument of the event listeners for a given event, in response to the return value of the modifier function.
const {EventEmitter} = require('events');
const modifyEvent = require('modify-event');
const emitter = new EventEmitter();
const eventName = Symbol('custom event name');
modifyEvent(emitter, eventName, val => `${val}b`);
modifyEvent(emitter, eventName, val => `${val}c`);
emitter
.on(eventName, listener)
.emit(eventName, 'a');
function listener(data) {
data; //=> 'abc'
}
Copyright (c) 2015 - 2019 Shinnosuke Watanabe
Licensed under the MIT License.
FAQs
Modify the value of the specific object's event
The npm package modify-event receives a total of 463 weekly downloads. As such, modify-event popularity was classified as not popular.
We found that modify-event demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.