fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Timofey Sitnikov 2021-05-18T11:15:35.006100Z

Good morning, I am tripping on the mutation data flow, for example:

#?(:cljs
    ;; client-side
    (m/defmutation delete-employee [{id :employee/id :as params}] ; 
      (action [{:keys [app state] :as env}]          ; 
        (swap! state update :employee/id dissoc id))
      (remote [env] true)                            ; 
      (result-action [{:keys [app state result]}]        ; 
        (println "Did it work?"))))  ; can I use result from server here?
  :clj
    ;; server-side
  (pc/defmutation delete-employee [env {id :employee/id :as params}] ; 
    {::pc/params #{:employee/id}}
    (db/delete-employee id))

;; the db/delete-employee returning

(defn delete-employee [id]
  (comment returns {:delete/result "OK"} if employee id is found)
  (comment returns {:delete/result "FAILED"} if employee id is not found))
When the delete-employee! mutation is triggered, assuming the result on the server can be {:delete/result "OK"} or {:delete/result "FAILED}, how does the the result get passed back to the client so that it can be used in the result-action section?

Timofey Sitnikov 2021-05-19T11:19:22.007900Z

@mroerni , one more question, why the

`delete-employee
instead of just
::delete-employee
?

Björn Ebbinghaus 2021-05-19T11:20:04.008600Z

The mutation name is a symbol, not a keyword.

1
Björn Ebbinghaus 2021-05-18T12:05:33.006300Z

(get-in env [:result :body `delete-employee])

Björn Ebbinghaus 2021-05-18T12:19:05.006700Z

You should read about result-action though. (https://book.fulcrologic.com/#_result_action) Then you can decide if you want to use ok-action, which is (per default) called when the network request has the status 200, or if you want to augment result-action to call ok-action only when {:delete/result "OK"}.

Timofey Sitnikov 2021-05-18T12:34:44.007Z

@mroerni, Thank you and honestly, I have a hard time reading the Fulcro book, there are soooo many angles to everything. The pointed answer is like hours and hours of reading.

Björn Ebbinghaus 2021-05-18T12:52:20.007200Z

I understand that. 🙂 @holyjak has written a blog post about error handling. https://blog.jakubholy.net/2020/error-handling-in-fulcro/ But I have to admit that it isn't very beginner-friendly as well.

❤️ 1