繁体   English   中英

批量放置 - 确保 store.subscribe 在所有放置完成之前不会更新

[英]Batch put's - ensure store.subscribe is not updated till all put's done

我必须做两个推杆。 渲染两者都强烈依赖于彼此。 这意味着第一次看跌必须与第二次同时发生。 目前,我所做的每一次put都会导致相关组件的重新渲染。 同时意味着, store.subscribeput都发生之前不能被触发。 我可以为此创建一个特定的操作,但我想知道是否有办法批量放置。 我尝试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) })),
]))

根据需要实现的目标,限制向订阅者发送通知和/或将某些操作标记为被动(仅状态 - 不引起通知)可能就足够了。 如果是这样的话 - 你可以试试这个: https ://www.npmjs.com/package/redux-notification-enhancer

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM