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

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

问题描述

所以在flux架构中,数据流如下:

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?

推荐答案

在您的情况下,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

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

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