Fork me on GitHub

Hi! Is it possible to implement something like “append-to-router” functionality? For example – I have a list of dynamic routes with handlers (["/foo/bar" handler] ["foo/bar/:id" handler] ...) and I would like to append new entry like ["/foo/bar/:id/:subid" handler] in runtime. So far I end up with wrapping router in mount/defstate and when I need to add something I’m restarting the router with (do (mount/stop) (mount/start)). Everything is working but looks a bit ugly.


@delaguardo interesting question. How & how often do the new routes get added? From some external event?


Not so often. In my case those routes comes from the database inserts which I’m tracking with event listener. And before router reloading my code is validating necessity of that reloading. just to not reload router with no reason


could the router be stored in an atom which is swapped on event and deferenced at routing?


Sure it can. In fact I'm already doing something similar with a small help from mount


something like that @delaguardo?


the raw-routes is unfortunate as the r/routes exposes the compiled results that need to be stripped away. Need to figure out how to do that more elegantly.


@ikitommi that looks promising! And much more elegant than my solution, thanks!