redispatch

0.0.2 • Public • Published

Redispatch

Build Status

Creates a function that delegates to a chain of registered dispatch functions. The registered functions are applied with the same arguments and context as the called function in the order they are registered. The first result from a registered function that is not undefined will be returned.

var dispatch = require('redispatch');
 
var empty = dispatch()
 
empty.register(function(){
  return null;
});
 
empty(null);
// null
 
empty([1,2,3]);
// null
 
empty.register(function(arr){
  if(Array.isArray(arr)){
    return [];
  }
});
 
empty(null);
// null
 
empty([1,2,3]);
// []
 

Note register can be called at any time. This can be used to extend default behavior of library functions. See underscore-transducer for examples.

License

MIT

/redispatch/

    Package Sidebar

    Install

    npm i redispatch

    Weekly Downloads

    1

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • kevinbeaty