Dispatch functions with late registration.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.jshintrc
.npmignore
.travis.yml
LICENSE
Makefile
README.md
package.json
redispatch.js

README.md

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