This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-26
Channels
- # admin-announcements (3)
- # beginners (44)
- # boot (48)
- # cljs-dev (2)
- # cljsjs (14)
- # cljsrn (2)
- # clojure (32)
- # clojure-android (1)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-russia (7)
- # clojure-spec (51)
- # clojure-uk (21)
- # clojurescript (9)
- # component (2)
- # cursive (4)
- # emacs (5)
- # funcool (1)
- # hispano (3)
- # hoplon (10)
- # immutant (14)
- # jobs (1)
- # jobs-discuss (4)
- # off-topic (15)
- # om (1)
- # onyx (1)
- # planck (36)
- # re-frame (2)
- # reagent (25)
- # spacemacs (2)
- # spirituality-ethics (10)
- # untangled (2)
- # vim (8)
- # yada (1)
is there a way to test if a spec exists for a namespaced key?
There is a 'registry' function
In master for the next alpha there will be 'get-spec'
I have defined an api spec for front end to communicate with backend. The messages include an auth token that I strip off soon and forward the rest of the message to internal handling functions. It would be cool to be able to create a spec on my backend that takes a spec defined for the API and removes aspects of it, like for example the auth-token key of the map. I guess the generic manipulating of a spec like a regular hash or something would be interesting.
@fenton: why not define the spec once for the back end, then define the spec for the front end as "back end" and "auth token"?
@seancorfield: I've pulled my api spec into a third project that is *.cljc with reader conditionals so it can be included as a library for both front and backend. I don't think I want to pull in my backend as a library to my front end....
Just the spec for the shared portion is what I'm suggesting.
So if your API and your back end traffic in a common subset of data, that spec needs to be external to both as a shared spec.
hmmm...might run into same problem about how to make a spec like that... can't merge a spec map.
You use s/and
to specify the API must conform to common spec and also to the auth token spec. You don't merge the maps.
Alex talked about that technique here a day or two ago.
I'm on my phone so I can't dig into code.
i didn't try that approach, but wondering if that doesn't make data that looks like: [{:auth-token "abc123"} {:method :search :search-term "blah"}]
Since maps are open, saying some data conforms to multiple map specs should still leave you with one map?
(Replete doesn't seem to have clojure.spec or I could try that out)
hmmm, not sure, making the (s/keys :req ...
might be a problem the :req
part...meaning each needs all?
@seancorfield: It does, but it is under cljs.spec
and slightly older at this point.
Ah, thanks @mfikes !
@fenton: if A needs key X and it needs key Y then that is additive and it needs keys X and Y - which is a merge and therefore what you want.
is (s/and (s/keys ...) (s/keys ...)) going to be special-cased to aid things like generation?
(s/conform (s/and (s/keys :req [::a]) (s/keys :req [::b])) {::a 1, ::b 2})
=> {:cljs.user/a 1, :cljs.user/b 2}
(In cljs.spec in Replete)
Dang, I love that I can test that on my phone while lazing in bed on a Sunday!!!
I can't tell if that is supposed to answer my question or not :)
I can try it myself though, let's see...
@seancorfield: And if we figure it out, clojure.spec
will act as an alias for cljs.spec
in bootstrapped ClojureScript π
It was for @fenton - I'm typing on my phone, excuse the slow responses.
@seancorfield: yeah, that looks good...
Replete is truly awesome.
nope, the generator doesn't work
@seancorfield: ahh googled it.
It is for lazy people who donβt want to crawl out of bed to their computer to start a REPL.
@gfredericks: the generator doesn't work for and with two keys?
seancorfield: right, which makes sense given what I know about s/and
it'd have to be special-cased to have any chance of succeeding
because the s/and generator just generates the first thing and filters based on matching the rest of them
with-gen
to the rescue! π
I have nothing.
there'll be a helper for this in my inevitable utility library