This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-18
Channels
- # announcements (6)
- # babashka (137)
- # beginners (115)
- # biff (4)
- # calva (24)
- # cider (1)
- # clj-kondo (15)
- # cljs-dev (18)
- # cljsrn (1)
- # clojure (43)
- # clojure-australia (1)
- # clojure-europe (11)
- # clojure-germany (3)
- # clojure-nl (3)
- # clojure-spec (40)
- # clojure-uk (6)
- # clojured (1)
- # clojurescript (24)
- # code-reviews (14)
- # core-logic (5)
- # cursive (24)
- # datahike (2)
- # datomic (3)
- # deps-new (9)
- # events (5)
- # figwheel-main (1)
- # fulcro (7)
- # helix (3)
- # honeysql (8)
- # jobs (4)
- # jobs-discuss (7)
- # lsp (59)
- # malli (9)
- # mid-cities-meetup (1)
- # nrepl (2)
- # off-topic (27)
- # portal (11)
- # re-frame (16)
- # reitit (1)
- # releases (12)
- # remote-jobs (4)
- # shadow-cljs (48)
- # spacemacs (1)
- # vim (9)
- # xtdb (14)
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?(get-in env [:result :body `delete-employee])
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"}
.
@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.
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.
@U4VT24ZM3 , one more question, why the
`delete-employee
instead of just
::delete-employee
?