了解嵌套箭头功能ES6

维克拉姆·巴布·纳吉尼尼
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 })
)

您能用多个箭头解释以上功能吗?

快乐

下面的代码:

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

等效于:

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

可以这样称呼它:

var something = logger(store)(next)(action);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章