This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-07
Channels
- # announcements (12)
- # aws (2)
- # beginners (233)
- # calva (68)
- # cider (23)
- # circleci (5)
- # clj-kondo (40)
- # cljsrn (4)
- # clojars (3)
- # clojure (200)
- # clojure-austin (1)
- # clojure-canada (1)
- # clojure-dev (16)
- # clojure-europe (1)
- # clojure-finland (1)
- # clojure-italy (4)
- # clojure-nl (16)
- # clojure-spec (3)
- # clojure-uk (102)
- # clojurescript (16)
- # cursive (14)
- # datomic (16)
- # figwheel-main (7)
- # graalvm (3)
- # hoplon (37)
- # jackdaw (23)
- # jobs-discuss (24)
- # joker (4)
- # kaocha (6)
- # keechma (64)
- # off-topic (66)
- # parinfer (1)
- # pedestal (7)
- # re-frame (7)
- # reagent (10)
- # reitit (45)
- # rewrite-clj (12)
- # shadow-cljs (1)
- # slack-help (8)
- # spacemacs (55)
- # sql (9)
- # tools-deps (9)
- # vim (7)
I am kinda fighting with coercion with plumatic/schema and reitit
I would expect this:
(def entity
{(schema/required-key :id) schema/Int
(schema/required-key :type) (schema/enum "company" "contact")
(schema/required-key :fields) {schema/Str schema/Str}})
To easily work but it fails on the {schema/Str schema/Str}
part. At first I even had {schema/Int schema/Str}
but I wanted to try out s/Str
to test it out.. I guess it makes keywords from them and I should use that. But I would expect it to do this for me with the "coercion"
Am I doing something really obvious wrong?
@mitchelkuijpers was about to say that “it should just work”, but actually - there are no coercers from keyword->* in Schema.
we seem to have extansions to those in our projects, should move those into schema-tools
(or Schema itself)
Ah ok, so that is the problem
That makes sense
I am happy to just add schema-tools
in the current project I’m working on, there are these:
(defn cond-matcher [preds]
(fn [x]
(or
(some
(fn [[f1 f2]]
(if (f1 x) (f2 x)))
preds)
x)))
(def keyword->int
{s/Int (cond-matcher
{string? stc/string->long
number? schema.coerce/safe-long-cast
keyword? (fn [x]
(try
(Long/valueOf (name x))
(catch Exception _ x)))})})
(def keyword->string
{String (cond-matcher {keyword? name})})
just for the types we have needed, should be polished and pushed out. Interested in doing a PR?
with reitit.frontend.history, is there any way I am missing to let it ignore clicks on certain a
elements? e.g we have links which trigger intercom, so this is handled by a 3rd party js, and we want reitit to not perform navigation on those. I see https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/history.cljs#L84 but it looks like this can not be easily customized?
It seems it will ignore external urls bij default?
I think it will also only do something if it matches a route
Sure you want a PR on reitit?
the spec counterparts are btw here: https://github.com/metosin/spec-tools/blob/master/src/spec_tools/transform.cljc
Ahh I see
I'll give it a go
Sorry quick question should i add something along the lines of:
(def +keyword-coercions+
{s/Int (comp safe-int keyword->number)
s/Num keyword->number
s/Bool keyword->boolean
#?@(:clj [Long (comp safe-int string->long)])
#?@(:clj [Double (comp double string->double)])})
There are already +string-coercions+
and +json-coercions+
I would change the current coercions so that they coerce from both strings & keywords, in a single sweep.
Ah ok will do
How should I format the code?
Nice, I have two questions though, do you rather have them on github or here?
I'll do it on github is better for visibility
For the json coercions would it be ok if they are the same as for the string-coercions? So that I re-use the string->x formats? Or do you want a stricter version that only does keyword->x and does not support strings?
json should not do conversions from strings to types that it can present itself. So no str->nbr for example.
Ok so str->number
is not ok, but keyword->number
is fine
I think I get it
Fixed the PR comments
merged the PR and added support for all the types: https://github.com/metosin/schema-tools/pull/57
(stc/coerce
{:1 {:true "1", :false "2"}}
{s/Int {s/Bool s/Any}}
stc/json-coercion-matcher)
; {1 {true "1", false "2"}}
Awesome
Hi all! Can you please explain why this code doesn’t work as expected:
(def routes
["/users/:id"
{:get {:name ::get-users
:parameters {:path {:id ::id}}}}])
(def router
(r/router routes))
(r/route-names router) ;; => []
route-names
return empty vector but should return [::get-users]
I see, thank you!