Open Hopding opened 7 years ago
I do this pattern on my projects, i.e. to separate "utility" functions into a separate file. I think it would help with making them more generic, and thus usable by other components/functions later on. I would thus agree with making a utilities file.
I would hold off moving the axios calls to a shared file until they are actually used in multiple places. I could see needing to call axios.get(api + '/skills/'
when adding a tmskill
but I'm not sure that we will handle the requests and errors the exact same way. If we get to that point and we are implementing it the same, finding a way to abstract it will make more sense.
We probably won't often handle the API responses the exact same way, but the idea would be to make the generic networking functions invoke callbacks. E.g. forEachTeamMember(api, teamMember => {/* stuff */})
or forAllTeamMembers(/* ... */)
, etc...
You could also pass an error callback.
I think it would be useful to add a utilities file for holding generic, often used functions to avoid duplicating them and to make them easy to find - similar to what we have in the backend. Networking functions are prime candidates for this.
For example, I've created the following functions for the PR I'm working on right now:
... and I will need to create more, similar to these. The function they perform could likely be used in other components in the future. They could also be made even more generic, perhaps invoke a callback once for each object in the response, say.
Thoughts?