This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-12
Channels
- # beginners (63)
- # boot (3)
- # braveandtrue (153)
- # cider (19)
- # cljdoc (2)
- # clojure (80)
- # clojure-dev (25)
- # clojure-italy (73)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-spec (67)
- # clojure-sweden (1)
- # clojure-uk (83)
- # clojurescript (56)
- # clojutre (11)
- # core-logic (37)
- # cursive (18)
- # datomic (14)
- # editors (10)
- # emacs (13)
- # figwheel-main (11)
- # fulcro (62)
- # graphql (11)
- # jobs (3)
- # klipse (1)
- # leiningen (6)
- # off-topic (91)
- # onyx (7)
- # pedestal (3)
- # portkey (5)
- # re-frame (14)
- # reagent (13)
- # remote-jobs (1)
- # shadow-cljs (111)
- # tools-deps (4)
- # yada (10)
@trailcapital well, indeed I'd like for the loading marker to be in the app-db, but for that, I somehow need to modify the app-db from the subscription to make sure the loading marker is there immediately for the sub
@alex340 the subscription is a function - it can fill in missing data (from the app-db) with the loading-marker - it doesn't have to modify the app-db
For example you could replace (get-in @app-db [:some :path])
from https://github.com/Day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md#some-code with (get-in @app-db [:some :path] ::loading)
.
This triggers when there's a change on the ::selected-scenario
signal:
(re-frame/reg-sub
::chart-data
:<- [::selected-scenario]
(fn [_ _]
This triggers when there's a change on the ::scenario-ids
signal:
(re-frame/reg-sub
::chart-data
:<- [::selected-scenario]
:<- [::scenario-ids]
(fn [_ _]
But this doesn't trigger when there's a change on the ::selected-scenario
or ::scenario-ids
signals:
(re-frame/reg-sub
::chart-data
:<- [::selected-scenario]
:<- [::scenario-ids]
(fn [_ _]
Is there some kind of trick to get a subscription to respond to the logical OR of signals?@bmaddy Could you share more of the code? The subscription should trigger when either signal changes (no tricks)
Yeah, but there's not much to show. I should have mentioned, I'm using re-posh. I wonder if there could be an issue on that side of things.
(re-posh/reg-sub
::selected-scenario
(fn [_ _]
{:type :query
:query '[:find ?id .
:where [_ :ui/selected-scenario ?id]]}))
(re-posh/reg-sub
::scenario-ids
(fn [_ _]
{:type :query
:query '[:find [?e ...]
:where [?e :scenario/name]]}))
I don't have much insight regarding re-posh, unfortunately. I'd maybe try to make a smaller example?
Yeah, that's probably the next step. It's nice to get it confirmed that things should be working the way I expect. Thank you @curlyfry!
@mccraigmccraig, @codonnell sure, but that's not equivalent. The data may be present in the app-db but stale, so it's not just a matter of indicating a loading marker when it's not there
Could you explain a bit more how you're putting this together? In my mind, the flow would be a bit like:
Initially, no data is loaded. When the subscription is derefed, an event is dispatched (async) which makes a remote request to fetch the necessary data. There is remote data in app-db, so the UI is in a loading state. (You could also explicitly initialize app-db to have the a loading value rather than make the data just be absent if you prefer.)
The response data is received, which dispatches an event that populates app-db. This triggers a rerender and the UI is populated with fresh data.
The data that was once fresh is now stale. (Why is it stale? Is there a time bound on how long data is fresh? Expired by mutation?) This transition from fresh to stale is captured by an event. If the stale-ness is due to time elapsed, you could :dispatch-later
a :mark-data-stale
event when the initial response is received. If it's due to mutation, you could dispatch this :mark-data-stale
event when the mutation is done. The :mark-data-stale
event dispatches a request to fetch fresh data and marks the data stale in app-db so the UI reflects this new reality.
I hope that was clear, and please let me know if I've made misconceptions about your use case. Also, it's your app and you're free to write it as you choose, so feel free to disregard!