-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Improve handler()
reference docs
#9261
Conversation
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, thank you @delucis ! Just one comment for your suggestion, but excellent as is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A concern about the example since we now show that the context is available. And some nitpicking (or quibbling... not sure about the right word, sorry).
Other than that, looks good to me! I agree that repeating the Since may not be necessary and could be unhelpful if in another version another parameter is added (it's easier to spot a new parameter if the others don't have Since).
handler: async (input, context) => { | ||
return `Hello, ${input.name}!` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea to show that context is also available, but shouldn't we update the example to include context?
This is a rough draft (I haven't taken the time to familiarize myself with Actions yet to find a better example) but maybe something like:
handler: async (input, context) => { | |
return `Hello, ${input.name}!` | |
} | |
handler: async (input, context) => { | |
if (!input.name) context.redirect(); | |
return `Hello, ${input.name}!` | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.redirect()
is not available on this version of context 😅
I also thought about this, but I mainly wanted to show it exists here without muddying the example. I think the reason context
was excluded in the initial version is that it’s mostly for pretty advanced use cases (for example it allows you to read context.locals
if you have some middleware), so I think it’s OK not to demonstrate it — just to mention its existence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I did say that I wasn't familiar enough with this feature. 😅 It's good for me so, no need for an overly complex example!
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Thanks @ArmandPhilippot — nitpicking and quibbling are both correct! (You could even do both simultaneously 😁) |
#9260) * i18n(fr): add Actions in `api-reference.mdx` See #9224 and #9254 * i18n(fr): add View Transitions section in api-reference.mdx See #9174 * i18n(fr): improve Actions handler documentation See #9261 * i18n(fr): update `view-transitions.mdx` See #9224 * i18n(fr): reword sentences around handler to make reading easier * i18n(fr): fix View Transitions capitalization where legit Co-authored-by: Thomas Bonnet <thomasbnt@protonmail.com> --------- Co-authored-by: Thomas Bonnet <thomasbnt@protonmail.com> Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
See withastro#9422 and it seems we missed some updates from withastro#9261
* i18n(fr): update `api-reference.mdx` See #9422 and it seems we missed some updates from #9261 * missing space Co-authored-by: Thomas Bonnet <thomasbnt@protonmail.com> --------- Co-authored-by: Thomas Bonnet <thomasbnt@protonmail.com> Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
Description (required)
This PR improves the
defineAction()
reference docs to better describe the signature of thehandler()
option and mention thecontext
argument.Also took the liberty of removing the extra
<Since>
components onhandler
andinput
sections — felt excessive to add those when they are properties ofdefineAction()
, which means they were added at the same time.