2017-09-04 58 views
1

我必须做两个放置。渲染都非常依赖于对方。意味着第一次放置必须与第二次放置同时发生。目前,我确实每个put都会导致相关组件的重新呈现。同时意味着,store.subscribe必须等到put发生时才能触发。我可以为此创建具体操作,但我想知道是否有批量投放的方式。我试图put.resolve和还有以下:批量放置 - 确保store.subscribe不会更新,直到完成所有放置完成

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后触发。

回答

2

我们使用redux-batched-actions为此。

建立之后,你就去。

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) })), 
])) 
+0

是否有内置任何内容,比如'put.resolve'?非常感谢您的回复,我正在等待一下。 – Noitidart

+0

非常感谢您对github的支持。我会尝试'redux-batch' - https://github.com/manaflair/redux-batch - 在我尝试使用redux-batched-actions之前,似乎更简单一点,我可以放置数组。 – Noitidart

+0

我为后人链接Github问题 - https://github.com/redux-saga/redux-saga/issues/1161 –

相关问题