Should flux stores, or actions (or both) touch external services?

前端 未结 6 495
轮回少年
轮回少年 2020-11-28 00:49

Should the stores maintain their own state and have the ability to call network and data storage services in doing so ...in which case the actions are just dumb message pass

6条回答
  •  遥遥无期
    2020-11-28 01:12

    gaeron's flux-react-router-demo has a nice utility variation of the 'correct' approach.

    An ActionCreator generates a promise from an external API service, and then passes the promise and three action constants to a dispatchAsync function in a proxy/extended Dispatcher. dispatchAsync will always dispatch the first action e.g. 'GET_EXTERNAL_DATA' and once the promise returns it will dispatch either 'GET_EXTERNAL_DATA_SUCCESS' or 'GET_EXTERNAL_DATA_ERROR'.

提交回复
热议问题