On the snippet of code below I am having a hard time understanding how result = next(action) doesn't end up being an infinite loop. Since the "last function" action => takes parameter action and calculates the result value based on the function that takes the next argument (next => action =>) that then call the function that takes the action parameter (next => action =>) AGAIN.
Essentially the recursiveness of this code is hard to understand.
import C from '../constants'
import appReducer from './reducers'
import { createStore, applyMiddleware } from 'redux'
const consoleMessages = store => next => action => {
let result
console.groupCollapsed(`dispatching action => ${action.type}`)
console.log('ski days', store.getState().allSkiDays.length)
result = next(action)
let { allSkiDays, goal, errors, resortNames } = store.getState()
console.log(`
ski days: ${allSkiDays.length}
goal: ${goal}
fetching: ${resortNames.fetching}
suggestions: ${resortNames.suggestions}
errors: ${errors.length}
`)
console.groupEnd()
return result
}
export default (initialState={}) => {
return applyMiddleware(consoleMessages)(createStore)(appReducer, initialState)