在流量架构中,谁是负责发送更新到服务器? [英] In the flux architecture, who is responsible for sending updates to the server?

查看:153
本文介绍了在流量架构中,谁是负责发送更新到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,在光通量架构,数据如下流程:

So in the flux architecture, data flows as follows:

View -> Action -> Dispatcher -> Store
 ^ <-----------------------------|

所以我们说的观点是一个评论框。当用户提交一个评论,一个addComment动作被触发,但应该在哪里的评论被发送到服务器?如果它发生在动作的功能,调度它之前,还是应该从商店的调度员接到操作时做什么呢?

So let's say the view is a comment box. When the user submits a comment, an addComment action is triggered, but where should that comment be sent to the server? Should it happen in the action function, before dispatching it, or should the store doing it when receiving the action from the dispatcher?

这两种情况缝像违反了单一职责格局。还是应该有两个CommentStores,一是LocalCommentStore和ServerCommentStore两个处理addComment行动?

Both cases seam like a violation of the single responsibility pattern. Or should there be two CommentStores, one LocalCommentStore and a ServerCommentStore that both handle the addComment action?

推荐答案

在您的情况下行动既负责发送未决诉讼或乐观更新到存储和发送呼叫到的WebAPI:

In your case Action is responsible for both sending a pending action or optimistic update to the store and sending a call to the WebAPI:

View -> Action -> Pending Action or optimistic update  -> Dispatcher -> Store -> emitEvent -> View 
               -> WebUtils.callAPI()

onWebAPISuccess -> Dispatcher -> Store -> emitEvent -> View
onWebAPIFail -> Dispatcher -> Store -> emitEvent -> View

这篇关于在流量架构中,谁是负责发送更新到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆