Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Improve API for nested <Get>s #3

Closed
micha-f opened this issue Jul 3, 2018 · 2 comments
Closed

Improve API for nested <Get>s #3

micha-f opened this issue Jul 3, 2018 · 2 comments

Comments

@micha-f
Copy link
Member

micha-f commented Jul 3, 2018

Is your feature request related to a problem? Please describe.
I think that it is

  • not obvious from looking at code that path="string" will be appended to the path(s) of parent <Get>(s)
  • not safe to assume that components will only make requests that fit with the nesting of paths

Describe the solution you'd like
I propose to update the API so that

<Get path="/persian"> // makes a request to /persian
<Get path={(parentPaths: string[]) => `${parentPath.join("/")}/persian`} > // makes a request to /cats/persian

where parentPaths is an array of the normalized paths (stripped of trailing /) of the parent <Get>s.

Describe alternatives you've considered

  1. parentPaths could also be a string of the concatenated parent paths. I believe however that the use of an array is more flexible if we go with nested <Get>s affecting each other.
  2. Alternatively or additionally we could introduce a <Path> component that affects the nesting while <Get>s don't affect each other's path at all. This would allow us to do things like this, too:
<Path path="/author/123">
  <Get path={ (path: string) => `${path}/bio`>
  <Get path={ (path: string) => `${path}/books`>
</Path>
@TejasQ
Copy link
Contributor

TejasQ commented Jul 4, 2018

Typically, components that nest also map to nested resources, hence the current design. I could also make the docs a little bit clearer about that API.

I think if we decide to implement your feature request, it'll have to be an add instead of a modify, which will be backwards compatible. So specced out, path could be a string, in which case it nests, or a function in which case it works the way you require. I'm still fairly unclear about the use case/need it'll be meeting.

From your second considered alternative, the <Path /> component, the only way its children would have access to the path from the Path component in that case is via function children. Your sample would actually look like

<Path path="/author/123">
{(path) => <>
  <Get path={`${path}/bio`}>
    {(data => <div>{data}</div>}
  </Get>
  <Get path={`${path}/books`}>
    {(data => <div>{data}</div>}
  </Get>
</>}
</Path>

I'm not sure that is easy to read. Seems to me like your preferred solution would be the way to go on this.

I'm curious: is there a particular use case you have in mind that the current API is not meeting?

@micha-f
Copy link
Member Author

micha-f commented Jul 4, 2018

Closing this after discussion with @TejasQ. You can always specify a different base in a Get and be completely independent from nesting.

@micha-f micha-f closed this as completed Jul 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants