gpt4 book ai didi

javascript - 为什么 Curry Redux 中间件 : state => next => action {} vs. (state, next) => action {}

转载 作者:行者123 更新时间:2023-11-30 21:05:06 26 4
gpt4 key购买 nike

阅读后 Redux's documentation在中间件和 source code 上关于 applyMiddleware,我不明白为什么中间件需要 curry 语法:

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

做不到同样的事情

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

applyMiddleware 中进行撰写调用:

dispatch = compose(...middleware)(middlewareAPI , store.dispatch)

最佳答案

可以找到与 Dan Abramov 的讨论 here对此。他说,

We could have made it (store, next) => action => () but I don't see a problem with just going all the way. You might want some configuration later, at which point options => (store, next) => action => () looks kinda arbitrary.

所以不,没有必要柯里化(Currying)参数。

关于javascript - 为什么 Curry Redux 中间件 : state => next => action {} vs. (state, next) => action {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com