JSPM

modify-event

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 373
  • Score
    100M100P100Q89084F
  • License MIT

Modify the value of the specific object's event

Package Exports

  • modify-event

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (modify-event) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

modify-event

npm version Build Status Coverage Status

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);

Installation

Use npm.

npm install modify-event

API

const modifyEvent = require('modify-event');

modifyEvent(eventEmitter, eventName, modifier)

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'
}

License

Copyright (c) 2015 - 2019 Shinnosuke Watanabe

Licensed under the MIT License.