4 ms·
In the design pattern mentioned at the end, there are some application state that are stored in both `updateRequest` and `state`, i.e. the data that is returned
by tuan 5y ago
In the design pattern mentioned at the end, there are some application state that are stored in both `updateRequest` and `state`, i.e. the data that is returned from the update response (stored in updateRequest) and is used to extend `state`. Having the same data stored in 2 different states seems error-prone. Which one is the source of truth when the 2 states accidentally get out of sync ? For example, nothing prevents extendState() to be called again to modify the `state` to something that is not the same as the value from update response.
- loh 5y agoThe API response ends up being the source of truth, in this case. If you wanted to prevent the user from updating the internal state while waiting on the API, you could certainly do that with a check for `updateThingRequest.status === 'pending'`.