redux - Normalizr to redux store - 多个 API 请求的最佳实践
问题描述
我正在使用带有 normalizr 的 redux。假设我们要加载客户的数据,但只能通过选择特定客户来加载,但最终可能会加载一些客户:
const foo = new schema.Entity("order");
const bar = new schema.Entity("infos");
const customer_data = new schema.Entity(
"cust_data",
{
orders: [foo],
infos: [bar]
}
{idAttribute: "custId"}
);
const normaled = normalize(dataFromOneRequest, customer_data);
假设服务器使用来自单个客户的 JSON 响应,我们将result
只有一个custId
和规范化的entities
.
假设应用程序的一部分显示客户列表,您可以深入了解细节。处理后续客户数据请求的最佳做法是什么?一旦第二个请求返回,来自第一个请求的数据已经被规范化。
将您的 redux 存储构建为[{customer: {normalizedData}}]
我们有点失去顶级result
数组的好处,或者以某种方式将结果和多个请求的实体添加在一起更好?
更新:当前策略
...
const myreducer = (state, action) =>
produce(state, draft => {
switch(action.type) {
case NEW_CUST_FETCH_SUCCESS:
_.mergeWith({}, draft.cust_data, action.newNormalizedReqResponse)
只是合并,但我认为它会导致不必要的重新渲染
解决方案
推荐阅读
- java - 将文本发送到 ClientName 的文本框,当单击 Addmore 按钮创建具有相同 id 和类名的新文本框
- html - RouterLink 似乎大多数时候只是重新加载当前页面
- sip - 如何从 FusionPBX 视频会议室获取视频流
- azure-devops - 使用 REST API 将测试结果与测试用例链接
- c# - PostSharp 没有在新的 csproj 中运行
- html - HTML:表格边框未显示在电子邮件中
- java - 索引 1 超出范围(SQL Server 异常)
- jquery - Jquery查找子对象包含并替换文本
- scala - Scala 中的 foreach(_ => ()) 是什么意思?
- javascript - 将 isLoading 传递给子组件