This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-05
Channels
- # announcements (1)
- # babashka (5)
- # beginners (151)
- # calva (43)
- # clj-kondo (23)
- # cljdoc (1)
- # cljs-dev (6)
- # cljsrn (10)
- # clojure (60)
- # clojure-australia (1)
- # clojure-europe (26)
- # clojure-gamedev (14)
- # clojure-nl (1)
- # clojure-spec (10)
- # clojure-uk (80)
- # clojurescript (66)
- # clojureverse-ops (4)
- # community-development (7)
- # conjure (8)
- # datomic (15)
- # deps-new (1)
- # docker (27)
- # emacs (2)
- # fulcro (13)
- # honeysql (13)
- # java (5)
- # jobs-discuss (43)
- # lsp (121)
- # luminus (13)
- # malli (1)
- # off-topic (73)
- # pathom (12)
- # polylith (29)
- # practicalli (4)
- # re-frame (35)
- # reagent (44)
- # remote-jobs (5)
- # rewrite-clj (2)
- # sci (7)
- # shadow-cljs (125)
- # sql (4)
- # tools-deps (9)
- # xtdb (5)
Are specs that I define in a CLJS namespace like sheluchin.ui
going to be available in CLJ tests? I'm getting Guardrails errors like this when invoking specced fns from my CLJ tests:
BUG: Internal error in expound or clojure spec.
Unable to resolve spec: :sheluchin.ui/note
java.lang.Exception: Unable to resolve spec: :sheluchin.ui/note
I would not expect them to be available
Right, looks to be that way. So then my question is where should specs be defined, and how do I get access to them in both clj and cljs while keeping things DRY?
Can you use a cljc file? Or create a cljc helper file and define the spec in there
I'm somewhat new to Clojure/Fulcro and haven't ever actually used cljc. I understand the concept, I think... basically you just create a cljc file and then wrap portions of code in conditional reader macros to indicate which compiler to use on that wrapped bit of code. If that's correct, which wrapper would I define the specs under?
You only have to wrap sections in the reader macros if you only want that code to be read by either only clj or only cljc So you just wouldn’t wrap it, and it’ll compile for both
You can check out some of the fulcro templates on GitHub that make heavy use of cljc if you want some examples too
No problem!
Writing this up to help my future self — it’s so helpful that on the client-side of a mutation, you can add more data to the AST that gets sent to the server via remote
. The Fulcro Book was a little vague on how to do this. Here’s what I did:
(m/defmutation move-card
; input: {:current-card [:trello-card/id :trello-list/id]
; :target-list [:target-list/id :target-board/id]
[{:keys [list-id card-id target-board-id target-list-id]
:as params}]
(action [{:keys [ref app state]}]
; ...)
(remote [{:keys [ref app state ast]
:as env}]
; look up full card in client database, and send it to server
(let [card (get-in @state [:trello-card/id card-id])
newast (assoc-in ast [:params :card] card)]
(println "move-card: remote: new-ast: " newast)
(-> env
(assoc-in [:ast] newast)
; this rc/nc command: let the resolver let everything true: elide nothing, which
; the default result handler will do
(m/returning (rc/nc ['*])))))
This ability to send more data to server was so much better than trying to stuff more data into the transaction — getting all that data into the component call site was proving quite problematic. In contrast, this was very easy. Nice!See also m/with-params
(you have params
, so you can update that and pass it to with-params
)
can anyone tell what I'm doing wrong?
(defsc ArtEditor [this {:keys [current-art] :as props}]
{:query [{[:current-art '_] (comp/get-query Art)}]
:ident (fn [] [:component/id :art-editor])
:route-segment ["art-editor"]
:initial-state (fn [_] {})}
(let [{:art/keys [uuid]} current-art]
(div :.ui.container.segment.four.column.stackable.grid
"Editing:" uuid (pr-str props))))
(defmutation edit-art
"edit art"
[{:art/keys [uuid]
:keys [component]}]
(action [{:keys [app state ref] :as env}]
(swap! state assoc :current-art [:art/uuid uuid])
(dr/change-route component ["art-editor"])))
I'm getting the error:
ERROR [com.fulcrologic.fulcro.components:730] - Props passed to app.ui.root/ArtEditor are of the type cljs.core/PersistentVector instead of a map. Perhaps you meant to `map` the component over the props? See
And also the output of props is:
[:component/id :art-editor]
When I'm expecting my art
entity. Hopefully that's enough info to help troubleshoot, if not, any hints where else to look? Thanks!