Skip to content
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

v4 Action statuses change to a single "status" property #37

Closed
nikitastryuk opened this issue Nov 15, 2023 · 3 comments
Closed

v4 Action statuses change to a single "status" property #37

nikitastryuk opened this issue Nov 15, 2023 · 3 comments

Comments

@nikitastryuk
Copy link

nikitastryuk commented Nov 15, 2023

Hey, first of all, huge thanks for this pckg! Good job!

Problem

Quick question/suggestion. What's the background of this change?

image

Single status string property is a step back in terms of DX imho. JSX with string conditions (like status === 'executing') looks messier and more code to write. Noticed, I started manually creating isExecuting consts (and some for other statuses) all over the project.

Old api vs New api

const { status } = useAction(action);
const isExecuting = status === 'executing';
const { status, isExecuting } = useAction(action);

Extra

Tanstack Query Api could be great inspiration (for naming things as well) - I assume community got really used to it in past years.

image
@zhouzi
Copy link

zhouzi commented Nov 17, 2023

I don't know about the actual background of this change but one issue with hasExecuted, isExecuting, hasSucceeded and hasError is that they are not discriminating.

From a static analysis standpoint they could be all true at the same time whereas status can only be in one state.

@TheEdoRan
Copy link
Owner

one issue with hasExecuted, isExecuting, hasSucceeded and hasError is that they are not discriminating.

Yes, this is exactly why I changed the API. Also, I think it's way cleaner to have just one status key.

Noticed, I started manually creating isExecuting consts (and some for other statuses) all over the project.

You can define an util function like this:

export function isExecuting(status: HookActionStatus): status is "executing" {
  return status === "executing";
}

Then import and use it in your Client Components. It's almost the same as having pre-v4 isExecuting key, the only difference is that you have to pass the action status to it.

@TheEdoRan
Copy link
Owner

Hope the code snippet above solved your problem. If you have any additional questions about this implementation, feel free to leave a comment here, and, if needed, I'll reopen the issue. Thank you!

TheEdoRan added a commit that referenced this issue Feb 8, 2024
Sometimes it's useful and more elegant to check the action status using a function instead of string
equality. This commit exports util functions to do that, while ensuring the same discriminated
behavior that the single `status` property provides to the user, thanks to TypeScript's type
predicates feature.

re #61, re #37
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

No branches or pull requests

3 participants