This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-28
Channels
- # announcements (1)
- # aws (1)
- # babashka (41)
- # beginners (21)
- # biff (7)
- # calva (102)
- # cider (8)
- # cljs-dev (1)
- # clojure (8)
- # clojure-bay-area (2)
- # clojure-dev (30)
- # clojure-europe (40)
- # clojure-norway (52)
- # clojure-sweden (9)
- # clojure-uk (5)
- # clojurescript (15)
- # cursive (7)
- # data-science (1)
- # datomic (23)
- # events (1)
- # fulcro (9)
- # humbleui (23)
- # hyperfiddle (46)
- # introduce-yourself (1)
- # jackdaw (2)
- # jobs (2)
- # london-clojurians (1)
- # malli (13)
- # off-topic (8)
- # re-frame (36)
- # remote-jobs (1)
- # shadow-cljs (4)
- # specter (4)
- # squint (1)
- # transit (4)
- # vim (1)
Is there a legitimate reason to use optional instead of :or
for malli specs in Biff? It seems like :or
gives you more flexibility with no downside because you can put nil in something, which is what I would expect optional to do. This would be an example of the difference
[:user/foo {:optional true} :string]
[:user/bar [:or :string :nil]]
I think there is a difference.
In the :or
case you will store the nil
attribute and in the :optional
case you won't need to store it. And I think that nil
may even be an invalid attr. I didn't check though.
Edit: I validated this and here is the result:
(ns playground.malli
(:require [malli.core :as m]))
(def schemas
[[:map [:user/foo {:optional true} :string]]
[:map [:user/foo [:or :string :nil]]]])
(def values
[{}
{:user/foo nil}
{:user/foo "hi"}])
(for [value values]
[value (->> schemas
(map #(m/validate % value)))])
Output:
([{} (true false)]
[#:user{:foo nil} (false true)]
[#:user{:foo "hi"} (true true)])
So... there is a difference because in the :or
case you'd be storing the nil
.yeah, basically up to you which you prefer to use; you could even do [:user/foo {:optional true} [:maybe :string]]
. I don't have a strong opinion either way; I just kinda like :optional
more for some reason
Am I missing something about reading after writes in biff? It sounds like biff/submit-tx
automatically awaits for the last result. But I am trying to read characters after deleting one and it still contains the missing character unless I read it a little later.
(defn delete-character [{:keys [path-params biff/db] :as ctx}]
(biff/submit-tx ctx
[{:xt/id (parse-uuid (:char-id path-params))
:db/op :delete}])
(character-list (get-characters db)))