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

Fix useGet url composition pattern #114

Merged
merged 2 commits into from
Apr 16, 2019
Merged

Conversation

fabien0102
Copy link
Collaborator

Why

By lazyness, I've choose url.resolve composition pattern when I implement the first version of useGet, the problem is that it required to add a trailing slash to the Provider.base to be able to use the library…

To resolve this, I update a bit the pattern, to permit more convenient url composition, not sure that is yet perfect but it will be test in our internals applications to validate the usage and pattern 😉

src/useGet.tsx Outdated
@@ -56,6 +56,13 @@ export interface UseGetProps<TData, TQueryParams> {
| number;
}

function resolvePath<TQueryParams>(base: string, path: string, queryParams: TQueryParams) {
const escapedBase = base.endsWith("/") ? base : `${base}/`;
const escapedPath = path.startsWith("/") ? path.slice(1) : path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escaped confuses me here - makes me think about url encoding, how about appendedBase and trimmedPath?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trimmed wins. 🎉

TejasQ
TejasQ previously approved these changes Apr 16, 2019
Copy link
Contributor

@mpotomin mpotomin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥!

@mpotomin mpotomin merged commit cd3ce81 into master Apr 16, 2019
@fabien0102 fabien0102 deleted the fix-use-get-url-composition branch April 16, 2019 11:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants