Fork me on GitHub

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

Tyler Nisonoff14:08:10

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?

Tyler Nisonoff14:08:40

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?

Tyler Nisonoff14:08:45

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

Tyler Nisonoff14:08:12

You can check out some of the fulcro templates on GitHub that make heavy use of cljc if you want some examples too


Interesting. Thanks for the advice. Seems clear now.

🙌 3

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)


Oh, that’s much nicer. Thx!!!

👍 3

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!