Fork me on GitHub
#reitit
<
2018-07-17
>
delaguardo13:07:10

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.

ikitommi16:07:29

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

delaguardo16:07:47

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

ikitommi16:07:26

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

delaguardo17:07:23

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

ikitommi17:07:35

something like that @delaguardo?

ikitommi17:07:28

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.

delaguardo18:07:48

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