简短的问题是:如果它是React / Redux应用程序,应用程序状态是否有 items
和 item
的两个属性,以及两个reducers,或者应用程序状态是否应该有一个属性 items
具有两个属性 all
和 item
,以及1个reducer?
详细信息:在React / Redux博客文章应用程序中,可以查看所有帖子的列表(摘要列表),用户可以单击任意行以查看包含完整博客文章内容的完整博客文章 .
所以在主减速机中:
const rootReducer = combineReducers({
posts: PostsReducer,
form: formReducer
});
posts
最初的位置:
const INITIAL_STATE = {
all: [],
post: null
};
请注意,对于 all
,它有一个发布数据数组,但只有 Headers 和类别(例如运动和自行车)和 does not have the blog content ,而对于 post
,它只有一个帖子的数据, but it does have the blog post's title, categories, and content (which may be 3000 words) .
相反,在主要状态下使用2个独立属性的优缺点是什么? (如下)
const rootReducer = combineReducers({
all: PostsReducer, // reducer for all
post: PostReducer, // reducer for one
form: formReducer
});
因为有两个组件(列表摘要和一个显示一个帖子)和两个动作,我倾向于在主状态中使用2个单独的reducer和2个不同的属性,但是我看到了使用1个reducer和1的示例属性包括 all
和 post
. 有什么利弊,我们应该实际使用一种方式而不是另一种方式吗?