alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

reducer里修改的状态不是实时更新的吗? #680

Open fangshengfy opened 4 years ago

fangshengfy commented 4 years ago

监听滚动的时候会因为好像状态更新异步的所以会重复触发dispatch

fangshengfy commented 4 years ago
onNotification: (ScrollNotification scrollInfo) {
  if (scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
    //滑到了底部
    print("滑动到了底部");

//这里的isCommentloadingMore在dispatch后修改了状态,但是状态没有实时更新 if (state.isCommentloadingMore==false) { if (state.isCommenthasMore==true) { dispatch(CommentActionCreator.loadComment()); } } } }

fangshengfy commented 4 years ago

现在的解决方法是在组件里加了一个叫lock的state来实时更新 if (lock == false && widget.state.isloadingMore == false) { if (widget.state.ishasMore) { setState(() { lock = true; widget.dispatch( MicroblogCommentDetailActionCreator.onGetMoreData()); });

fangshengfy commented 4 years ago

这种问题会不会在react里也存在?因为setState也是异步更新的,但vue中是不是就不会存在了?

fangshengfy commented 4 years ago

我的理解是redux的dispatch和reducer都是同步的,flutter的state的修改也是同步的,会出现这种情况是因为fish redux做了像react的setState的优化?