7
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?

5
  • Function returning function returning function. Commented Jan 31, 2018 at 11:12
  • 1
    use babeljs repl if you can't read ES6 Commented Jan 31, 2018 at 11:24
  • Want to understand arrow functions in ES6. - @Jaromanda X Commented Jan 31, 2018 at 11:28
  • Yes. But if you understand es5 but not that fluent in es6 babel can help you learn Commented Jan 31, 2018 at 11:34
  • Will just add the link for Babel to this which is babeljs.io - perfect for seeing what the older equivalent of the new JS is - thanks @JaromandaX Commented Jan 31, 2018 at 12:56

1 Answer 1

24

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.