This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-15
Channels
- # announcements (2)
- # babashka (137)
- # beginners (96)
- # calva (3)
- # cider (11)
- # clj-kondo (8)
- # cljs-dev (161)
- # cljsrn (21)
- # clojure (78)
- # clojure-europe (47)
- # clojure-france (1)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-spec (24)
- # clojure-uk (9)
- # clojuredesign-podcast (4)
- # clojurescript (39)
- # conjure (2)
- # core-async (27)
- # cursive (36)
- # datomic (54)
- # emacs (6)
- # figwheel (9)
- # figwheel-main (46)
- # fulcro (25)
- # graalvm (8)
- # helix (30)
- # hoplon (6)
- # hugsql (3)
- # jobs (5)
- # leiningen (7)
- # luminus (12)
- # nrepl (20)
- # off-topic (20)
- # pedestal (16)
- # re-frame (14)
- # reagent (3)
- # reitit (3)
- # remote-jobs (5)
- # rum (25)
- # shadow-cljs (60)
- # spacemacs (10)
- # vim (2)
- # xtdb (36)
So it's not intended, for example, to use things like ::mygameobject-id on other namespaces of specific 'gameobject' each?
Among the things I'm playing around with is having a ::gameobject-id
defined in some-ns.game
and use that in some-ns.game.dog
and some-ns.game.bat
, each of which has an :id
which is a gameobject-id. Am I doing things in a non-Clojure way?
:: means to auto-resolve the keyword in the context of the current namespace
so if you're using ::id in different namespaces, you'll get different keywords specific to each namespace, and there is no conflicting name
and if I want to use the same spec definition for each? just use a common function?
you can (s/def ::id ::common/gameobject-id)
in each namespace
so have one common spec and then make namespaced specs that refer to it
removing the potentially confusing auto-resolving keywords, something like:
(s/def :common/gameobject-id string?)
(s/def :some-ns.game.dog/id :common/gameobject-id)
(s/def :some-ns.game.bit/id :common/gameobject-id)
I was trying to do just that and it didn't work, and not it works. Great. Maybe I had a funky repl state before :man-shrugging: Thanks!
I see that when I do something like
(s/def ::thingy (s/keys :req-un [:common/gameobject-id]))
Then the thingy gets an :id
property, and not { :common/gameobject-id "whatever" }
Which is good for me
(or maybe :gameobject-id
, I am mixing up some namings between this chat and my actual code)
it doesn't "get" a :gameobject-id property, it describes a map expected to have a :gameobject-id key which matches the :common/gameobject-id spec
I meant that when I conform something to ::thingy, the keyword in the conformed map is { :gameobject-id "something" }
and not { :common/gameobject-id "something" }
. I guess it omits the namespace from the keyword?
:req-un means "required unqualified key"
(as opposed to :req)
so more importantly it's validating the incoming map expecting an unqualified key
conforming just follow that
I seeeee I made a thingy2 now with :req and it wants the fully qualified key
Interesting and cool.
Do I have to require common for using :common/gameobject-id or something?
Oh nevermind.