批量放置 - 确保 store.subscribe 在所有放置完成之前不更新
Batch put's - ensure store.subscribe is not updated till all put's done
我必须做两次看跌期权。渲染两者都强烈依赖于彼此。这意味着第一个 put 必须与第二个同时发生。目前,我所做的每 put
都会导致相关组件的重新渲染。同时意味着,在 put
都发生之前,store.subscribe
不能被触发。我可以为此创建一个特定的操作,但我想知道是否有一种方法可以批量放置。我尝试了 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
之后被触发。
为此我们使用 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) })),
]))
根据需要实现的目标,限制对订阅者的通知可能就足够了 and/or 将某些操作标记为被动(state-only - 不引起通知)。如果是这样的话——你可以试试这个:https://www.npmjs.com/package/redux-notification-enhancer
我必须做两次看跌期权。渲染两者都强烈依赖于彼此。这意味着第一个 put 必须与第二个同时发生。目前,我所做的每 put
都会导致相关组件的重新渲染。同时意味着,在 put
都发生之前,store.subscribe
不能被触发。我可以为此创建一个特定的操作,但我想知道是否有一种方法可以批量放置。我尝试了 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
之后被触发。
为此我们使用 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) })),
]))
根据需要实现的目标,限制对订阅者的通知可能就足够了 and/or 将某些操作标记为被动(state-only - 不引起通知)。如果是这样的话——你可以试试这个:https://www.npmjs.com/package/redux-notification-enhancer