Socket
Book a DemoInstallSign in
Socket

redispatch

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redispatch

Dispatch Functions with late registration

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

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

Keywords

dispatch

FAQs

Package last updated on 20 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts