Is triggering an action in the store bad practice?

后端 未结 1 503
感动是毒
感动是毒 2021-02-09 06:45

Stores are supposed to handle the events triggered by actions and emit the change to the listening view controllers.

Is it ok for them to trigger actions as well, for ex

相关标签:
1条回答
  • 2021-02-09 07:30

    The short answer: Yes - triggering an action in the store is a bad practice.

    And with the current version of the Dispatcher in react I don't even think that it's possible to dispatch a new action while dispatching, as you would when calling a new action in the store.

    I properly a bit of a boy-scout when it comes to the flux pattern, but I have been pushing react projects to production where we decided to give it a full go and take the use of actions, stores, and events to the extreme regarding flux.

    I think you should never makes the stores call new actions, as this can lead to a very weird behavior when the projects starts to evolve. It's right that it doesn't really "break" the data-flow thinking because you still (should) handle the response as normal and then it's all fine. But if you really have the need for this I would rather call what fetchNewData() calls directly inside the first action.

    0 讨论(0)
提交回复
热议问题