This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-18
Channels
- # aws (1)
- # babashka (35)
- # beginners (52)
- # biff (4)
- # calva (55)
- # cider (19)
- # clojure (54)
- # clojure-dev (3)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (2)
- # clojurescript (9)
- # code-reviews (3)
- # datahike (1)
- # fulcro (1)
- # funcool (4)
- # graalvm (21)
- # gratitude (2)
- # java (5)
- # jobs (2)
- # joyride (1)
- # kaocha (13)
- # malli (2)
- # off-topic (22)
- # other-languages (11)
- # pathom (4)
- # re-frame (35)
- # reagent (3)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (42)
- # sql (18)
- # tools-deps (72)
- # web-security (6)
- # xtdb (15)
So some people seem to be sharing specs between clj/cljs. They define their specs in a cljc file and validate on both sides.
What I'm confused about is how they combine this with namespaced keys. If my spec has namespaced keys, and I want to send a form from the client that has those same keys, the cljs-http
chops off the namespaced part before sending it to the backend. Now I can't validate whatever was sent because it's invalid without the namespace
You have a few options:
1. Send the data as EDN or Transit if you make the POST yourself (e.g. with js/fetch or similar), that will maintain the namespaces.
2. Implement a server-side handler that receives data from a specific form and translates the data to the fully qualified data model.
3. Use :req-un
and :opt-un
to use the specs on unqualified keys, but that doesn’t work if there are collisions, and you loose the benefit of namespaces, so investigate the two other options first.
Thanks, I'll probably just go with edn for now
If you have lots of data then transit is much faster than EDN and is a 100% compatible drop in replacement (no code change required - so you can do it later when needed). Main downside is Transit is less human readable - but can still be sort of read by humans in small quantities.
Yeah, I always go with Transit in such cases. And Transit can be human-readable if you disable compression by using the :json-verbose
format.
+1 for using transit for serialization speed/compactness while preserving all the clj native data structure goodies
I've generally found shipping transit between clojurescript frontends and clojure backends pretty great except for one odd gotcha around UUIDs: https://github.com/cognitect/transit-cljs/pull/10 Not entirely sure whether the status of that one has changed but it's a relatively trivial trip hazard to deal with once you know about it.