This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-15
Channels
- # aleph (24)
- # announcements (8)
- # babashka (27)
- # beginners (55)
- # biff (4)
- # calva (32)
- # cider (5)
- # clj-kondo (11)
- # clojure (59)
- # clojure-android (3)
- # clojure-australia (1)
- # clojure-belgium (6)
- # clojure-dev (21)
- # clojure-europe (26)
- # clojure-nl (1)
- # clojure-norway (17)
- # clojurescript (19)
- # css (1)
- # data-science (10)
- # datahike (17)
- # events (3)
- # figwheel-main (4)
- # honeysql (1)
- # hugsql (5)
- # hyperfiddle (1)
- # jobs (1)
- # leiningen (3)
- # lsp (6)
- # malli (5)
- # meander (4)
- # nbb (6)
- # off-topic (87)
- # pathom (19)
- # portal (2)
- # re-frame (4)
- # reitit (6)
- # releases (1)
- # remote-jobs (3)
- # shadow-cljs (29)
- # sql (8)
- # tools-deps (6)
- # xtdb (7)
Folks, any tips on handling things with promises?
I have quite a lot of situations where my answers are inside promises and I'm 100% sure they won't break (they are only inside of promises because of the tool I have to use, not because they're truly async) but creating a reg-event-fx
, with reg-fx
and them reg-event-db
just for this situations is becoming tedious...
> creating a reg-event-fx, with reg-fx and them reg-event-db just for this situations is becoming tedious...
You can have a single reg-fx
and a single reg-event-db
for all promises - you'd just pass them the right data and that's it. You'd still need ad-hoc reg-event-fx
handlers to pass just the right data, but that's the case with any soluiton.
I feel I can have some concurrency problems with this approach :thinking_face:.
I honestly don't really know how would this work - a reg-event-fx
that triggers this reg-fx
, with... the promise result? The function that I want to call? I'm not sure how to wire this...
Probably something like:
(rf/reg-fx ::make-a-promise-you-can-keep
(fn [{:keys [f then catch]}]
(-> (fn-that-returns-a-promise)
(.then (fn [result]
(rf/dispatch (conj then result))))
(.catch (fn [error]
(rf/dispatch (conj catch error)))))))
This is without that extra reg-event-db
so it still requires a custom event for each then
/`catch`. But if all your promises do is store some data in app-db, then you can also make a generic event or two and then then
/`catch` can become paths in app-db.