Closed piranha closed 5 years ago
Oh, that's not intented. I guess it would work if the default options were provided via a no-args function instead. I guess there isn't a test for this...
Is there any need for expand to be provided as an option though? It seems to me protocol should be enough - of course, that would limit customization options, but OTOH isn't limiting options in some ways a goal of a good library design? :-)
Excellent point.
Protocol is good but it has opinions about expanding keywords & functions, so it is made interchangeable. Not sure if overriding Protocol dispatch definitions would work, but it would be global side-effect and one couldn't have different routers with different expansion under same ClassLoader. Much cleaner to allow the implementation to be changed.
Here's an example use case btw: https://metosin.github.io/reitit/advanced/shared_routes.html#using-custom-expander
Example problem with non-pluggable impl: https://github.com/dakrone/cheshire/issues/77
Interested in a PR for this? ;)
Yeah, the way with option of course is much more customizable... Okay, do you think (let [route-expand (:expand opts expand)] ...
is the right way to go? :-)
Would making default-router-options
a defn work?
Ah! I guess so! :-)
Sorry for not coming up with patch, wasn't happy with my test and got distracted. :\
There is
reitit.core/Expand
protocol, which in theory provides extension point for adding various types of handlers (etc). I have tried adding support for vars like that:This code executes with no problems and if I
(prn reitit.core/Expand)
in repl, I seeclojure.lang.Var
there, but compilation of routes still fails withNo implementation of method: :expand of protocol: #'reitit.core/Expand found for class: clojure.lang.Var
.What fixes it though is passing
{:expand reitit.core/expand}
as an option for router. It seems that havingexpand
as a default parameter inrouter
captures protocol state as it is defined in reitit.core source.Not sure what's the best way to proceed, but it feels like this is not intended behavior. :-)