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

Route handler return value #711

Open
NHQ opened this issue Jul 12, 2021 · 3 comments
Open

Route handler return value #711

NHQ opened this issue Jul 12, 2021 · 3 comments

Comments

@NHQ
Copy link

NHQ commented Jul 12, 2021

Where in the source code does choo handle the return value of route handler functions (the hyperx html)? I see where where the router sets the handler, but I don't see where choo takes that return value and renders it.

@tornqvist
Copy link
Member

tornqvist commented Jul 13, 2021

It's in Choo#_prerender, right here: https://github.com/choojs/choo/blob/master/index.js#L259

@NHQ
Copy link
Author

NHQ commented Aug 6, 2021

Thanks. FWIW, I think the router auto-rendering is an anti-pattern. Everywhere else, one does the rendering manually (see beginner's guide). By returning htmlx in route functions, there is no direct way to attach logic to elements after they are appended. I use MutationObserver to listen for renders, and then make a callback out of the app emitter in my templates. Am I doing it wrong?

@tornqvist
Copy link
Member

Having automatic rendering on navigation I think is very much the responsibility of a framework such as choo. For reacting to updates and routing on the component level, you'd probably want to use nanocomponent (which comes with choo). It has lifecycle hooks for load/unload behavior among some other niceties. See the documentation here: https://github.com/choojs/choo#components

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

2 participants