我必须做两次投注。渲染两者都强烈依赖于彼此。意思是第一次放置必须同时发生在第二次。目前,我每做put
一次都会导致相关组件的重新渲染。同一时间意味着,在store.subscribe
发生之前,不得触发put
。我可以为此创建一个特定的操作,但我想知道是否有一种批量放置的方法。我尝试了put.resolve
以及以下内容:
yield all([
put(updateEntity(ENTITYS.COMMENT, id, comment)),
put(updateEntity(ENTITYS.STORY, storyId, entity => ({ commentIds:entity.commentIds.map(commentId => commentId === id ? comment.id : commentId) })))
]);
但这不起作用,store.subscribe
在每个put
之后被触发。
答案 0 :(得分:2)
设置完成后你就去了。
import { batchActions } from 'redux-batched-actions';
yield put(batchActions([
updateEntity(ENTITYS.COMMENT, id, comment),
updateEntity(ENTITYS.STORY, storyId, entity => ({ commentIds:entity.commentIds.map(commentId => commentId === id ? comment.id : commentId) })),
]))