Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding nested arrow functions ES6 [duplicate]

const logger = store => next => action => {
    let result
    console.groupCollapsed("dispatching", action.type)
    console.log('prev state', store.getState())
    console.log('action', action)
    result = next(action)
    console.log('next state', store.getState())
    console.groupEnd()
    return result
}

const store = applyMiddleware(logger)(createStore)(
    combineReducers({ colors, sort })
)

Would you please explain the above function with multiple arrows?

like image 357
Vikram Babu Nagineni Avatar asked Jan 31 '18 11:01

Vikram Babu Nagineni


1 Answers

The code below:

const logger = store => next => action => { return 'something'; }

Is the equivalent of:

const logger = function(store) { 
    return function(next) {
        return function(action) {
            return 'something';
        }
    }
}

And it can be called like below:

var something = logger(store)(next)(action);
like image 53
Faly Avatar answered Nov 05 '22 23:11

Faly