Skip to content

chore: refactored to reduce repetition #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fearphage
Copy link
Contributor

This is building on top of the getUrl extraction. All the code is doing relatively the same thing so I refactored it all into a wpFetch wrapper around fetch. This drastically reduces the repetitiveness of the code as well as enables a central location to insert error handling, request tracing, etc.

PS. I'm relatively sure the the explicit return types of Promise<Post> for instance aren't needed anymore with this implementation, but I kept them there to confirm the contract is maintained since I couldn't find any tests to update.

Copy link

vercel bot commented Aug 25, 2024

@fearphage is attempting to deploy a commit to the 9d8 Team on Vercel.

A member of the Team first needs to authorize it.

const response = await fetch(url);
const posts: Post[] = await response.json();
return posts;
return wpFetch<Post[]>("/wp-json/wp/v2/posts", { author: filterParams?.author, tags: filterParams?.tag, categories: filterParams?.category });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not very familiar with WordPress, but if the /wp-json/wp/v2/ part of the path is constant, that could also be moved into the wpFetch wrapper. Repeating it doesn't really seem to be serving any purpose.

@youngbloodcyb youngbloodcyb requested a review from brijr August 27, 2024 03:46
Copy link

vercel bot commented Sep 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-wp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 17, 2024 2:36pm

@youngbloodcyb
Copy link
Contributor

opting to keep as is on this one. I like the abstraction in theory but I think for people coming into the codebase, seeing the explicitness behind each API call makes it easier to read

fearphage added a commit to fearphage/next-wp that referenced this pull request Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants