This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-23
Channels
- # announcements (2)
- # beginners (165)
- # boot (11)
- # cider (11)
- # clj-kondo (7)
- # cljdoc (1)
- # cljsrn (5)
- # clojure (120)
- # clojure-dev (21)
- # clojure-europe (3)
- # clojure-france (1)
- # clojure-italy (62)
- # clojure-nl (8)
- # clojure-spec (26)
- # clojure-uk (40)
- # clojuredesign-podcast (1)
- # clojurescript (3)
- # cursive (2)
- # data-science (2)
- # datomic (10)
- # emacs (2)
- # figwheel-main (1)
- # fulcro (17)
- # graphql (5)
- # hoplon (5)
- # jackdaw (15)
- # jobs (2)
- # juxt (1)
- # luminus (5)
- # off-topic (1)
- # onyx (11)
- # pathom (4)
- # pedestal (1)
- # re-frame (4)
- # reagent (11)
- # reitit (1)
- # remote-jobs (5)
- # shadow-cljs (48)
- # spacemacs (2)
- # specter (4)
- # sql (24)
- # tools-deps (25)
- # vim (82)
highly possible this has been asked before, but is there any re-frame add-on that could spit out a subscription graph as graphviz?
Is there a documented solution for Warning: unmountComponentAtNode(): The node you're attempting to unmount was rendered by another copy of React
? I’m using reagent 0.8.1, day8.re-frame 0.10.8, and day8.re-frame-10x 0.4.2, day8.re-frame/async-flow-fx 0.1.0, and day8.re-frame/tracing 0.5.1
@atticmaverick Well, you could do this without even using an interceptor..
You just need one condition in :try-different-server
to either dispatch again with a different uri
or to handle the failure as you want:
(rf/reg-event-fx
:http-post
(fn [{db :db} [_ uri]]
{:http-xhrio
{:method :post
:uri uri
:params {}
:response-format "foo"
:format "bar"
:on-success [:success]
:on-failure [:try-different-server]}}))
(rf/reg-event-fx
:success
(fn [_ _]
"do what you want"))
(rf/reg-event-fx
:try-different-server
(fn [{db :db} _]
(if (:second-attempt-fired? db)
{:db (assoc db :error "both servers failed")}
{:db (assoc db :second-attempt-fired? true)
:dispatch [:http-post (:server-b-uri db)]})))
If you can't help but using an interceptor a solution would be this:
(def replay-event
(re-frame.core/->interceptor
:id :replay-event
:after (fn [context]
(when (get-in context [:effects :db :fire-second?])
(-> context
(assoc-in [:effects :dispatch] [:http-post])
(assoc-in [:effects :db :uri] "/new-uri")
(assoc-in [:effects :db :fired-twice?] true))))))
(rf/reg-event-fx
:http-post
(fn [{db :db} _]
(let [uri (:uri db)]
{:http-xhrio
{:method :post
:uri uri
:params {}
:response-format (ajax/transit-request-format)
:format (ajax/transit-request-format)
:on-success [:success]
:on-failure [:try-different-server]}})))
(rf/reg-event-fx
:success
(fn [_ _]
"do what you want"))
(rf/reg-event-fx
:try-different-server
[replay-event]
(fn [{db :db} _]
(when-not (:fired-twice? db)
{:db (assoc db :fire-second? true)})))