gpt4 book ai didi

javascript - 为什么我们在 redux applyMiddleware 函数中执行 slice() 和 reverse() ?

转载 作者:行者123 更新时间:2023-12-01 03:34:58 25 4
gpt4 key购买 nike

official doc of redux middleware .

它有一个 redux applyMiddleware 函数的展示案例:

function applyMiddlewareByMonkeypatching(store, middlewares) {
middlewares = middlewares.slice()
middlewares.reverse()

// Transform dispatch function with each middleware.
middlewares.forEach(middleware =>
store.dispatch = middleware(store)
)
}

我不明白为什么它在这里执行 slice()reverse()

// This can make a deep copy of middlewares parameter.
middlewares = middlewares.slice()

但是为什么我们要进行深层复制,以及为什么我们必须反转数组?

这让我很困惑。请帮忙!

最佳答案

我在这里找到了答案:

Redux: The Middleware Chain

它说:

Finally, I'd like to fix the order in which middlewares are specified. They are currently specified in the order in which the dispatch function is overridden. However, it would be more natural to specify the order in which the action propagates through the middlewares.

如果我们看到 action 中的中间件顺序经过顺序,就会更加清晰。

关于javascript - 为什么我们在 redux applyMiddleware 函数中执行 slice() 和 reverse() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44342948/

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