This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-07
Channels
- # announcements (11)
- # architecture (2)
- # babashka (84)
- # beginners (226)
- # calva (7)
- # chlorine-clover (4)
- # cider (29)
- # clara (17)
- # clj-kondo (23)
- # cljs-dev (58)
- # cljsrn (60)
- # clojure (172)
- # clojure-europe (24)
- # clojure-finland (2)
- # clojure-italy (6)
- # clojure-nl (8)
- # clojure-spec (4)
- # clojure-uk (22)
- # clojurescript (44)
- # conjure (39)
- # core-async (64)
- # cursive (76)
- # data-science (15)
- # duct (3)
- # emacs (2)
- # events (5)
- # fulcro (30)
- # helix (4)
- # jackdaw (5)
- # juxt (1)
- # kaocha (1)
- # leiningen (4)
- # off-topic (9)
- # pathom (22)
- # re-frame (9)
- # reagent (33)
- # reitit (3)
- # ring (10)
- # ring-swagger (2)
- # shadow-cljs (192)
- # spacemacs (27)
- # specter (2)
- # sql (59)
- # vim (2)
If I understood correctly, in a pure reagent app with a single r/atom
, any component dereferencing the ratom would be redraw every time any part of the ratom is modified.
When using rf/subscribe
, does it still work that way? If I have a component that subscribes to something that returns (:foo db)
and I change db :bar
, is the component re-drawn?
@dromar56 It should work the same way. If the return value of the subscription changes, component will redraw
I'm using a React component that expects a callback returning a Promise as one of its properties. I implemented it like this:
(fn [data]
(js/Promise. (fn [resolve reject]
(letfn [(cb [[event args] queue]
(cond (= event :app.events/editor-save-success)
(do (resolve)
(js/console.log (str "RESOLVE:" args) )
(rf/remove-post-event-callback cb))
(= event :app.events/editor-save-failure)
(do (reject "POST failed")
(js/console.log (str "REJECT:" args))
(rf/remove-post-event-callback cb))))]
(rf/add-post-event-callback cb)
(js/console.log "saving")
(rf/dispatch [:editor/save data])))))
The :editor/save event handler uses re-frame.http-fx to do a POST and triggers save-success / save-failure depending on the result.
This works but it seems wrong to hook into re-frame's event system like that. Is there a better way ?I would definitely try to wrap that component in a plain Reagent component, and then use that wrapped component in re-frame.
Also you could pass resolve
and reject
to the :editor/save
event. It wouldn't be great, but still better than fiddling with add-post-event-callback
.
To my taste, it's much better than post event callbacks. Apart from being quite ugly (adding a callback that removes itself), it's also prone to concurrency issues when you dispatch more than one :editor/save
. It may be fine in this case, but the pattern itself is not great.