Posted on #chestnut on Slack by @luchini
I’m trying to wrap my head around Stuart Sierra’s component architecture and how it has been implemented as part of Chestnut.
Something that’s been quite troublesome for me is coding server-side and client-side simultaneously. First, it’s not immediately clear that a separate Ring is spawned on port 10555 (while Figwheel’s own http-kit is spawned on port 3449). Second, if I run cljs-repl I lose my server context unless I connect to it via nREPL separately. Lastly, every time I make a change to the server, I need to issue a reset that basically drops everything and I lose my cljs-repl session.
I have the feeling that I’m doing something terribly wrong because Clojure development via REPL is usually a lot more fun than this. The current workflow I’ve described above has drained the joy out of iterative development.What are your thoughts?
Some good points here that could use some discussion.
Figwheel port (3449) vs Chestnut port (10555)
This split has been there since the early versions of Chestnut. IIRC later on we started using Figwheel as the HTTP server when in dev mode, which meant that either port would work. Now with the Component approach we want to start/control our own instance, which means the distinction is back. I’ve heard from a few people this has been confusing. Even though Chestnut prints that it starts on
localhost:10555, people are simply used to connect to
I’ve run into this myself, and have started added a small ring handler to Figwheel that redirects to 10555. Maybe we can do something similar in Chestnut.
Changing routes requires a system restart
Any changes to the route factory functions are only picked up when restarting the system. If your environment has reloaded.repl support baked in (like CIDER) then this isn’t a big deal. I’ve gotten used to pressing
C-c C-x regularly. But it’s still annoying and it trips people up.
A workaround here that I’ve used is to give the endpoint component a handler function that calls the routes factory on every request. This works quite well, main question is how to do that in a clean way so this happens in dev mode but not in prod.
Switching between CLJ and CLJS repls
Again when using CIDER I don’t really perceive this as a problem (
cider-jack-in-clojurescript gives you both a CLJ and CLJS repl, so you can evaluate front- and backend forms without switching), but in other environments you end up doing a lot of
:cljs/quit to switch between contexts… Not sure what the best approach is in this case. I would probably recommend that people take Figwheel out of the system and run a
lein figwheel as a separate process.
Suggestions (and pull requests) to improve any of this are very welcome!