gpt4 book ai didi

normalizr - 为什么标准化状态形状中需要一个全为 `ids` 的数组?

转载 作者:行者123 更新时间:2023-12-02 11:27:02 27 4
gpt4 key购买 nike

comments : {
byId : {
"comment1" : {
id : "comment1",
author : "user2",
comment : ".....",
},
"comment2" : {
id : "comment2",
author : "user3",
comment : ".....",
},
"comment3" : {
id : "comment3",
author : "user3",
comment : ".....",
},
"comment4" : {
id : "comment4",
author : "user1",
comment : ".....",
},
"comment5" : {
id : "comment5",
author : "user3",
comment : ".....",
},
},
allIds : ["comment1", "comment2", "comment3", "commment4", "comment5"]
}

在上面的示例中,我是否需要包含它 api 包含它。我认为这样你可以更快地进行计数,你可能可以排序,但通常我不明白是否会影响性能。

最佳答案

这不是 Redux 所要求的,这是一个标准化的东西。为了回答你的问题,JavaScript对象can't be replied upon to retain sort order in certain situations 。将 id 放入数组中可以让您保留规范化之前存在的排序顺序。

Quote from co-maintainer of Redux and author of "normalizing state shape section" of Redux docs :

As for the ID arrays, while JS engines now have a fairly standardized process for iterating across keys in an object, you shouldn't rely on that to define ordering. Storing arrays of IDs allows you to define an order for items.

关于normalizr - 为什么标准化状态形状中需要一个全为 `ids` 的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46124964/

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