This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-11
Channels
- # announcements (1)
- # aws (2)
- # beginners (140)
- # boot (67)
- # cider (50)
- # clojure (64)
- # clojure-berlin (1)
- # clojure-conj (1)
- # clojure-france (2)
- # clojure-italy (2)
- # clojure-nl (8)
- # clojure-norway (6)
- # clojure-seattle (1)
- # clojure-spec (81)
- # clojure-sweden (2)
- # clojure-uk (131)
- # clojurescript (147)
- # clojutre (7)
- # cursive (40)
- # datomic (34)
- # editors (5)
- # emacs (7)
- # events (9)
- # figwheel (18)
- # figwheel-main (1)
- # fulcro (2)
- # instaparse (1)
- # jobs (3)
- # leiningen (1)
- # luminus (10)
- # lumo (1)
- # mount (6)
- # off-topic (12)
- # pedestal (4)
- # portkey (7)
- # re-frame (8)
- # reagent (21)
- # reitit (10)
- # ring-swagger (5)
- # shadow-cljs (140)
- # specter (4)
- # tools-deps (53)
- # uncomplicate (1)
ok, so this might be a stupid question - is it safe to manipulate app-db in any way from a reg-sub-raw subscription?
I'm following https://github.com/Day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md and kicking off some backend requests, effectively, from the subscription handler. I'd like to get a loading marker of sorts. I was planning on putting it inside an ratom within the subscription handler, but there's some issues with how data comes back - if the data coming back ends up triggering (A) a re-frame dispatch and (B) a synchronous callback, it's likely that the callback clearing the loading state (B) happens before the dispatch merging the actual data into the app-db (A) occurs, leaving me in a brief state where the subscription doesn't say it's loading anymore, but the data isn't (yet) in the app-db either
If the loading marker could be in the app-db, that would work just fine, in that the dispatch'ed event can clear it as it merges in the data. However, that means I somehow need to set the loading marker in the app-db from the subscription handler itself
Could you put the loading marker in the view?
(defn view
[]
(if-let [data @(re-frame/subscribe [:key ...])]
[display-data data]
[loading-marker]))
otherwise, I'd make the dispatch callback remove the loading at the same time as it associates the data in app-db
Imagine the app-db is something like
{:loading? true
:data nil}
;; My callback dispatch (which accepts the fetched data)
(defn handle-callback
[{:keys [db]} [_ data]]
{:db (assoc db :loading? false :data data)}