atomicdata-dev/atomic-data-browser

Refactor fetch functions - clarity & consistency

joepio opened this issue · 0 comments

  • We have a store.fetchResource, retuning void, 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 to client.fetchResourceHTTP. Contrary to the store version, this fetches the resource always using HTTP. That's an important distinction.
  • Remove the store argument from fetchResourceHTTP. It should not add to the store, that's what store.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. 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.
  • Let store.fetchResource return the fetched resource, instead of void. This is often useful.
  • Check where the functions are used, make sure they use the correct one