This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-16
Channels
- # announcements (7)
- # babashka (1)
- # beginners (25)
- # calva (7)
- # cider (15)
- # clj-kondo (13)
- # cljdoc (14)
- # clojure (151)
- # clojure-europe (4)
- # clojure-hamburg (2)
- # clojure-italy (22)
- # clojure-nl (57)
- # clojure-spec (12)
- # clojure-uk (6)
- # clojuredesign-podcast (5)
- # clojurescript (12)
- # core-async (8)
- # cursive (26)
- # datascript (9)
- # datomic (92)
- # emacs (4)
- # fulcro (7)
- # graalvm (1)
- # graphql (2)
- # instaparse (3)
- # jobs (1)
- # jvm (2)
- # kaocha (6)
- # nrepl (3)
- # off-topic (5)
- # re-frame (45)
- # reagent (5)
- # reitit (18)
- # ring (1)
- # shadow-cljs (89)
- # slack-help (9)
- # spacemacs (2)
- # sql (54)
- # tools-deps (75)
- # vim (28)
- # xtdb (17)
- # yada (31)
I have a subscription that doesn't seem to be updating, and I'm a bit off into the weeds with my signal function
within the subscription:
I have an app-db
that is structured like {:games {<game-id> {:game/players [<player 1> <player 2> etc]}}}
. I have some subscriptions that look like:
(rf/reg-sub
:games/games
(fn [db _]
(:games db)))
(rf/reg-sub
:games/game
:<- [:games/games]
(fn [games [_ game-id]]
(get games game-id)))
(rf/reg-sub
:game/players
(fn [[_ game-id] _]
(rf/subscribe [:games/game game-id]))
(fn [game _]
(get game :game/players)))
I've updated the App-db, and the subscription to :game/players
has the old information. Is there a normal cause for this? I'm new to the signal functions.Subscription still looks like:
Where App-db looks like:
Show's the frisk diff of the event in question
@david.folkner I don’t think you should be calling subscribe
inside of a subscription quite like that
Yeah. It works if I refresh or change some other state in the app-db, but if you look at the pictures in the thread, the subscription is out of date.
Does it have anything to do with where/how I call the actual subscribe (rf/subscribe [:game/players <game-id>])
?
looks like you are passing a parameter in the signal , does that work? I haven't seen it in the docs
From the docs it seems to indicate that you can: https://github.com/day8/re-frame/blob/04433cfa60a8c8116e2b6aefd8fd253014285229/src/re_frame/subs.cljc#L262
yeah , that's the return, but you are destructuring the parameters and consuming it in the signal-fn
(rf/reg-sub
:game/players
(fn [[_ game-id] _]
(rf/subscribe [:games/game game-id]))
(fn [game _]
(get game :game/players)))
But maybe I've extrapolated. To me that's the entire reason to write the signal function.
I mean this one
(fn [[_ game-id] _]
(rf/subscribe [:games/game game-id]))
can you use the parameters or is nil?I thought it was good to build out subscriptions in a cascading way like I have. I could clearly re-write it as
(rf/reg-sub
:game/players
:<- [:games/games]
(fn [games [_ game-id]]
(get-in games [game-id :player])))
`But then I'm recomputing everytime any game changes, not just my specific game.
Hmmm...It works if any other changed to the DB made after, but not if that's the only change.
;; one sugar pair
2 (let [[marker vec] input-args]
(when-not (= :<- marker)
(console :error err-header "expected :<-, got:" marker))
(fn inp-fn
([_] (subscribe vec))
([_ _] (subscribe vec))))
So that is exactly the same as I'm doing?
I think it is no possible, since you can't pass the below game-id to the signal function
it just calls subscribe vec , but the vec has no idea of the value of game-id, because that is supplied in the compute-fn
Which I've done I thought?
(fn [[_ game-id] _] <- the parameter is ignored
(rf/subscribe [:games/game game-id <- this is nil ]))
an easy way to verify would be to console.log the parameters passed to the signal function
Signal function takes in [query-vec dynamic-vec]
where the computation function takes in [db query-function]
Not nil. that is working properly.
It works great, just doesn't think it needs to update when the app-db changes. Then when the app-db changes more, its smart enough to go update them.
For example: if I dispatch the player changes, app-db gets updated but subscriptions dont. Then if I dispatch something completely different (like a route) the subscription updates.
Yeah...I'm baffled.
Since that part of re-frame is pretty automatic.
silly question , but did you deref them in the view? if it's lazyseq, can you try to wrap in a doall?
doall did it.
My god. I feel dumb.