Fork me on GitHub
#fulcro
<
2021-05-18
>
Timofey Sitnikov11:05:35

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?

Björn Ebbinghaus12:05:33

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

Björn Ebbinghaus12:05:05

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 Sitnikov12:05:44

@U4VT24ZM3, 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 Ebbinghaus12:05:20

I understand that. 🙂 @U0522TWDA 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.

❤️ 3
Timofey Sitnikov11:05:22

@U4VT24ZM3 , one more question, why the

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

Björn Ebbinghaus11:05:04

The mutation name is a symbol, not a keyword.

3