big*_*ind 1 javascript architecture single-responsibility-principle reactjs-flux
因此在通量架构中,数据流如下:
View -> Action -> Dispatcher -> Store
^ <-----------------------------|
Run Code Online (Sandbox Code Playgroud)
所以我们假设视图是一个评论框.当用户提交注释时,会触发addComment操作,但该注释应该在何处发送到服务器?它应该在动作函数中发生,发送之前,还是商店在收到调度员的动作时这样做?
这两种情况都像是违反单一责任模式.或者是否应该有两个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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
686 次 |
最近记录: |