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

docs: Add example of using AsyncLocalStorage to README #47

Conversation

chimame
Copy link
Contributor

@chimame chimame commented Dec 8, 2024

Thanks for the great library.
Using this library has made Remix even easier to use.

I realized that I could use AsyncLocalStorage, so I added an example of how to use it to the README.

If you don't mind the usage method, why not add it?

@yusukebe
Copy link
Owner

yusukebe commented Dec 9, 2024

Hi @chimame

Looks good! But have you ever tried the Context Storage Middleware? I've never tried it, but it will work. If so, this middleware will be suitable for this use-case instead of using AsyncLocalStorage from scratch.

https://hono.dev/docs/middleware/builtin/context-storage

@chimame
Copy link
Contributor Author

chimame commented Dec 9, 2024

Thank you for checking.

I changed it to a usage example that uses Context Storage Middleware. I confirmed that the code I wrote actually works.

README.md Outdated
import { getContext } from 'hono/context-storage' // It can be called anywhere for server-side processing.

export const loader = () => {
const cookie = getContext<Env>().headers.get('Cookie')
Copy link
Owner

Choose a reason for hiding this comment

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

I'm just curious. Is it difficult to get a Header object in loader without this way using AsyncLocalStorage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's very simple.

export const loader = ({ request }: LoaderFunctionArg) => {
  const cookie = request.headers.get('Cookie')
}

Remix can be retrieved easily like this. Originally, I wanted to write it in the server processing function called from loader rather than in loader, but I was worried that doing so would increase the amount of sample program description in the README.

Shall I write it in an easy-to-understand way?

README.md Outdated Show resolved Hide resolved
@yusukebe yusukebe changed the title Add example of using AsyncLocalStorage to README docs: Add example of using AsyncLocalStorage to README Dec 10, 2024
Copy link
Owner

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

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

LGTM!

@yusukebe
Copy link
Owner

Thanks, @chimame !

Looks good. I'll merge this now.

@yusukebe yusukebe merged commit 6e61599 into yusukebe:main Dec 10, 2024
8 checks passed
@chimame chimame deleted the add-example-of-using-asynclocalstorage-to-readme branch December 10, 2024 08:39
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