Refactor fetch functions - clarity & consistency
Closed this issue · 0 comments
joepio commented
- We have a
store.fetchResource
, retuningvoid
, which also does either HTTP or WebSocket fetching, and always adds to the store. - We have a
client.fetchResource
, returning a resource, which uses HTTP and returns a resource. It optionally adds it to the store, if a store is passed.
This is confusing. When would you use the one or the other?
Here's a suggested set of improvements:
- rename
client.fetchResource
toclient.fetchResourceHTTP
. Contrary to thestore
version, this fetches the resource always using HTTP. That's an important distinction. Remove the. We still need the store, because of parsing nested resources. However, maybe it could return an array of resources, first one being the requested resource.store
argument fromfetchResourceHTTP
. It should not add to the store, that's whatstore.fetchResource
should do. Also, we don't need the store to get the agent - we could simply explicitly pass the agent if we need auth- Let
store.fetchResource
return the fetched resource, instead ofvoid
. This is often useful. - Check where the functions are used, make sure they use the correct one