Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

how to know the state is changed in flutter in fish redux

Now I am setting the state in reducer like this using fish redux:

HomeListDefaultState _onSetArticleIds(HomeListDefaultState state, Action action) {
  final HomeListDefaultState newState = state.clone();
  ArticlePayload payload = (action.payload as ArticlePayload);
  newState.articleListState.articleIds = payload.articleIds;
  newState.articleRequest = payload.articleRequest;
  newState.currentStoriesType = state.currentStoriesType;
  if (payload.articleRequest.pageNum == 1 && payload.articleIds.isNotEmpty) {
    newState.articleRequest.offset = payload.articleIds.reduce(max);
  }
  return newState;
}

when I dispatch an action in effect like this:

Future initArticles(Action action, Context<HomeListDefaultState> ctx) async {
  HomeListDefaultState homeListDefaultState = ctx.state;
  ArticleRequest articleRequest = homeListDefaultState.articleRequest;
  articleRequest.pageNum = 1;
  articleRequest.offset = null;
  List<int> ids = await Repo.getElementIds(articleRequest);
  if (ids != null) {
    ctx.dispatch(HomeListDefaultActionCreator.onSetArticleIds(ids, articleRequest));
  }
}

sometimes the state change not trigger the page rerender(when the UI not rerender and just only dispatch action), why the UI not rerender when dispatch action? so how the fish redux to konw the state changed(if the newState.articleListState.articleIds have 10 element and replaced by new another 10 element, it will treated as changed or not)?

question from:https://stackoverflow.com/questions/65896245/how-to-know-the-state-is-changed-in-flutter-in-fish-redux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...