Route handler return value
NHQ opened this issue · comments
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.
It's in Choo#_prerender
, right here: https://github.com/choojs/choo/blob/master/index.js#L259
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?
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