Deduplicate API calls
Requirements
- [x] This is a feature request and not a bug report. Otherwise, please create a new bug report instead.
- [x] Please check to see if this request (or a similar one) already exists.
- [x] It's a single feature. Please don't request multiple features in one issue.
Describe the feature you'd like
There are a lot of handle methods in top-level components which simply call an API endpoint and then update the global state. Many of these could be moved into a single file api.tsx and deduplicated. Here is one example. Others can be found by grepping for await HttpService.client. In some cases it may be necessary to add a callback for file-specific state changes.
The tricky part about this is that while these handlers are all identical, they call this.setState or update this.isoData. Is there a good way to pass this into the generic handler with the right type so that those work? Otherwise I would use a callback, but then its not much simpler than before.
You don't want to pass the entire this object, that's very dangerous, might ruin your immutable objects, and your strict typing.
I've found there's not really a clean "generic" way to handle this for different screens and different objects that need to be updated. There's also few enough screens, and the data structure on them is different enough, that its usually not worth it.
The main thing is that you need to preserve immutability, so the only real way to handle this in a well-typed way, is to add helper functions that return new objects, that you can then set easily to the top level state objects using setState
Check out editPersonViewPersonNote and the editCommentsSlimLocked for examples.