1

Been playing around with adding state management to my application, and was hoping for a little clarification on best practices for organizing normalized data.

Based on the documentation in the Redux Docs a common pattern is to organize things like "authors" and "books" under "entities" inside your state.

However, most examples that I've come by doesn't fit this pattern. It seems as though a common practice is placing "authors" and "books" on their own inside the state rather than within "entities".

Just hoping to get some clarification on this, and an understanding of how to get "authors" and "books" within "entities" to fit the structure of the example docs.

4

1 回答 1

0

我写了整个“Structuring Reducers”文档部分,所以我会说我有资格回答:)

将所有不同的标准化数据放在一个entities键下只是一个建议。如果您希望将每个项目类型放在状态树的顶部,那很好,取决于您。

我在规范化文档页面中的一些建议是基于Redux-ORM库的组织方式。它生成一个reducer 函数,为您的不同项目类型定义所有“表”,因此reducer 函数通常成为根reducer 中的一个切片(通常命名为ormor entities)。

有关使用 Redux-ORM 的更多信息,您可能需要阅读我的“Practical Redux”教程系列,其中展示了使用 Redux-ORM 的一些技术,并在示例应用程序中演示了它的用法。

于 2017-06-20T16:23:39.890 回答