fish-redux icon indicating copy to clipboard operation
fish-redux copied to clipboard

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

Open fangshengfy opened this issue 5 years ago • 5 comments
trafficstars

fangshengfy avatar Jun 13 '20 11:06 fangshengfy

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

fangshengfy avatar Jun 13 '20 11:06 fangshengfy

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 avatar Jun 13 '20 11:06 fangshengfy

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

fangshengfy avatar Jun 19 '20 03:06 fangshengfy

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

fangshengfy avatar Jun 19 '20 03:06 fangshengfy

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

fangshengfy avatar Jun 19 '20 03:06 fangshengfy