3

Can anyone explain what the code is doing here

return () => next => action => {
  const callAPI = action[CALL_API];

  if (typeof callAPI === 'undefined') {
    return next(action);
  }

  let { endpoint } = callAPI;
  const { types, bailout } = callAPI;

It is initially returning a function but I don't get why there are two further fat arrows after the first.

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
dagda1
  • 26,856
  • 59
  • 237
  • 450

2 Answers2

2

If the arrow function has only one parameter, then the parameter around that is optional. You just need to have enough parenthesis to understand them better.

return () => (next) => (action) => {

it returns a function, which when invoked returns another function which accepts one parameter, next. Now when that function is invoked, it returns another function, which accepts another parameter action.

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
1

That code can be rewritten like below,

return function() { 
   return function(next) { 
      return function(action) {

It seems that the outer function returns a function with parameter next and that returns another one function with parameter action. That code in the link that you given has not minified, but that seems to be obfuscated.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130