因此在 flux 架构中,数据流如下:
View -> Action -> Dispatcher -> Store
^ <-----------------------------|
假设 View 是一个评论框。当用户提交评论时,会触发 addComment 操作,但应该将该评论发送到服务器的何处?它应该发生在 Action 函数中,在调度它之前,还是应该在从调度程序接收到 Action 时存储?
这两种情况看起来都违反了单一责任模式。或者应该有两个 CommentStore,一个 LocalCommentStore 和一个 ServerCommentStore 都处理 addComment 操作?
最佳答案
在您的情况下,Action 负责向商店发送未决操作或乐观更新并向 WebAPI 发送调用:
View -> Action -> Pending Action or optimistic update -> Dispatcher -> Store -> emitEvent -> View
-> WebUtils.callAPI()
onWebAPISuccess -> Dispatcher -> Store -> emitEvent -> View
onWebAPIFail -> Dispatcher -> Store -> emitEvent -> View
关于javascript - 在 flux 架构中,谁负责向服务器发送更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26816906/