何时将更新推送到 REST 后端

When to push updates to REST back-end

这个问题可能比较笼统,但我还是不问了。我有一个 REST 后端和一个使用 Redux、Axios 和 Thunk 的 React 前端。我正在将数据从后端拉到前端。我现在要编写可以在前端编辑从后端提取的数据的部分。我提取的数据是货币汇率列表。数据由currency coderatedate组成。

数据如下所示:

EUR    1.12    2016-10-03
USD    1.00    2016-10-03
GBP    1.29    2016-10-03

在我将编辑的前端,假设 EUR 的比率从 1.121.14

  1. 我是否应该先更新我的 state(映射到 props) 前端,然后将更新推送到 REST 后端。
  2. 我是否应该先将更新推送到 REST 后端,然后再拉取? 数据再次从后端刷新 state?
  3. 我应该用其他方式来做吗?

欢迎提出任何建议。

Should I first update my state (which is mapped to props) in the front-end and then push the update to the REST back-end.

如果在推送到服务器之前更新状态,这不包括推送失败的情况。您首先需要确定服务器更新成功。


Should I first push the update to the REST back-end and then pull the data again from the back-end and thereby refresh state?

如果一次只有一个客户端可以更新数据(如果服务器在推送处理期间没有进行更改合并)那么在推送之后客户端已经包含与服务器相同的数据,并且您不需要为同步做额外的拉取.