redispatch
v0.0.2
Published
Dispatch Functions with late registration
Downloads
3
Maintainers
Readme
Redispatch
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