React/Flux way to handle permission sensitive actions with login flows

后端 未结 3 995
后悔当初
后悔当初 2021-02-08 20:24

I have been playing with React/Flux, and I am having trouble wrapping my head around the \'Flux Way\' for handling permission-sensitive actions.

Overarching question: W

3条回答
  •  长情又很酷
    2021-02-08 20:51

    As FakeRainBrigand suggested in his answer, you'd want to just check that the user has a valid session before creating a comment by first retrieving that value from the SessionStore:

    case CommentConstants.ADD_COMMENT:
      if (SessionStore.getUser()) {
       createComment(action.data);
      }
      break;
    

    But to preserve the comment so that it gets created after the user logs in, I would create a collection of pending comments in the CommentStore, and then later, in a callback to the login verification and session creation, dispatch a new action to inform the CommentStore that the user has now logged in. Then the CommentStore can respond to that by creating real comments out of the pending ones.

提交回复
热议问题