fn-listener

0.5.6 • Public • Published

fn-listener

Installation

$ npm i fn-listener

Basic Usage

const listen = require('fn-listener').listen;
let add = (a, b) => a + b;
let cb1 = (result) => console.log("O K", result);
let cb2 = (result) => console.log("2nd O K", result + 1);
add = listen(add, cb1);
add(1, 2);
=> O K 3

Other Usage

const listen = require('fn-listener').listen;
let identity = (elem) => elem;
let cb1 = (result, index, callbackCollection) => {
    return callbackCollection[1](result * 3);
}
let cb2 = (result) => {
    return Math.sqrt(result);
}
identity = listen(identity, [cb1, cb2], {returnCallback: true, argMap: (elem) => elem *2 });
identity(2);
//maps the arguments before being passed into the function
//Uses a map and passes all of them into the function.
//Can be used to mutate a function into something which builds off the original function
=> [ 3.4641016151377544, 2 ]

License

MIT

Free Software, Hell Yeah!

Package Sidebar

Install

npm i fn-listener

Weekly Downloads

0

Version

0.5.6

License

MIT

Last publish

Collaborators

  • tomzer0