我正在使用 redux-thunk 和 normalizr 来创建数据模式 . 首先,我从获取调用中获取一个账单列表(未显示),然后对于响应中的每个项目,我使用账单ID在单独的API调用(如下所示)中获取与该账单相关的一些条款 . 外部提取响应中未提供该数据 .
我正在为每个账单采用标准化的术语实体,在我发送到州之前,我用一个包含相关账单列表的副本替换每个实体对象 .
(下面的代码工作正常 . )我的问题是:如果我用自己的副本替换每个 termEntities[key]
并添加了 relatedBills
属性,那是否算作变异?在调度之前是否可以使用normalizr实体数据,或者这是不好的做法?
谢谢!
export function fetchBillDetails(billId) {
return dispatch => {
return fetch(`${API}/${billId}`)
.then(response => response.json())
.then(json => {
const terms = json.terms;
const normalizedTerms = normalize(terms, arrayOfTermSchema);
const termEntities = normalizedTerms.entities.terms;
for (const key in termEntities) {
if (termEntities.hasOwnProperty(key)) {
termEntities[key] = Object.assign({}, termEntities[key], {
relatedBills: billId
})
}
}
dispatch(receiveBillTerms(
billId,
normalizedTerms.entities,
normalizedTerms.result
));
});
}
}