This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-15
Channels
- # announcements (8)
- # beginners (65)
- # calva (25)
- # cider (11)
- # clj-kondo (9)
- # cljsrn (14)
- # clojure (103)
- # clojure-europe (15)
- # clojure-greece (1)
- # clojure-italy (28)
- # clojure-nl (39)
- # clojure-spec (9)
- # clojure-uk (28)
- # clojuredesign-podcast (37)
- # clojurescript (56)
- # cursive (41)
- # data-science (10)
- # datomic (25)
- # duct (1)
- # emacs (1)
- # events (3)
- # figwheel-main (7)
- # fulcro (9)
- # graalvm (7)
- # graphql (10)
- # jobs (2)
- # nrepl (17)
- # off-topic (40)
- # quil (12)
- # reitit (11)
- # remote-jobs (5)
- # rum (2)
- # shadow-cljs (387)
- # sql (22)
- # tools-deps (8)
- # vim (26)
- # xtdb (47)
- # yada (9)
@hackeryarn Thanks for the suggestion! Reload middleware seems to be reloading the namespaces only on request. But it would be nice to have it reload automatically on file change.
Also it is using (require <ns> :reload)
which will not work properly if you're using a maven or clojars lib, and you're modifying a local copy of it. In this case (load-file ...)
would be more appropriate.
is it possible to use reitit/match-by-name
with coercion
? i've only seen examples for reitit/match-by-path
and some quick tests make me think coercion and match-by-name don't jive.
for example, :page/num
is not coerced to an integer here:
(def my-router
(reitit/router
[["/" {:coercion reitit.coercion.spec/coercion}
["{page/num}" {:name :page-num
:parameters {:path {:page/num integer?}}}]]]))
(reitit/match-by-name my-router :page-num {:page/num "2"})
=>
#reitit.core.Match
[:template "/{page/num}"]
[:data {...}]
[:result nil]
[:path-params {:page/num "2"}]
[:path "/2"]
@joshkh should work, first do the match and then apply the coercion like described in https://cljdoc.org/d/metosin/reitit/0.3.10/doc/coercion/coercion-explained#full-example. Not at computer, so didn't test thou.
both match-by-name
and match-by-path
return same Result
, which is the arg for the coercion.
hmm. i modified the full-example to use Spec coercion, and this time added coercion/coerce!
to the resulting Match, but it returns nil:
; with `coercion/coerce!`
(let [test-router (reitit/router
["/:company/users/:user-id" {:name ::user-view
:coercion reitit.coercion.spec/coercion
:parameters {:path {:company string?
:user-id int?}}}])]
(coercion/coerce! (reitit/match-by-name test-router ::user-view {:company "ECorp" :user-id "666"})))
=>
nil
@joshkh hmm.. sorry, can't check that out before Friday, something different in the returned match.