This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-14
Channels
- # announcements (10)
- # architecture (4)
- # atom-editor (1)
- # babashka (53)
- # babashka-sci-dev (118)
- # beginners (82)
- # biff (12)
- # calva (19)
- # clara (13)
- # clerk (20)
- # clj-commons (25)
- # clj-kondo (6)
- # cljdoc (19)
- # cljs-dev (3)
- # clojars (2)
- # clojure (71)
- # clojure-art (2)
- # clojure-europe (68)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-uk (3)
- # clojured (19)
- # clojurescript (34)
- # clr (19)
- # cursive (11)
- # emacs (14)
- # fulcro (3)
- # helix (2)
- # holy-lambda (2)
- # honeysql (27)
- # hyperfiddle (39)
- # malli (2)
- # off-topic (83)
- # polylith (4)
- # rdf (22)
- # re-frame (20)
- # reitit (4)
- # rewrite-clj (14)
- # shadow-cljs (17)
- # slack-help (2)
- # tools-deps (45)
- # xtdb (3)
should this https://github.com/day8/re-frame/blob/master/docs/FAQs/UseASubscriptionInAnEventHandler.md#the-better-way still work? I tried the interceptor workaround, but still getting the warning from using subscribe outside reactive context (as per issue #740)
or is there a way to get subscription value for a given app db value? there are some subscriptions chains that have logic I would rather not duplicate
I made the following hack workaround to get the value of a sub:
(defn- get-subscription-value [db sub]
(let [handler-fn (re-frame.registrar/get-handler :sub (first sub))]
(handler-fn db sub)))
(defn subscribe-val
"Get value of subscription for the given db."
[db subv]
(with-redefs [re-frame.subs/subscribe (partial get-subscription-value db)]
@(rf/subscribe subv)))
you can pass a db value and a subscription vector to that and it returns the value (bypassing cached values)That hack should still produce a warning if one of those subs uses a signal sub. And if it doesn't, it's not entirely correct because the cache wouldn't be purged. I think.
I ended up writing my own wrappers or alternative variants for most of re-frame API that I use. Can definitely recommend - it gives great flexibility.
E.g. for this particular case, I've introduced a dynamic variable that, when set, is just like subscribe
but without caching.
ah yes, it seems re-frame.subs/subscribe
should have ^:dynamic
meta for it to work in advanced compilation
Right. I pretty much never use with-redefs
so my memory is always fuzzy when it comes to it.
Although, docstrings in both CLJ and CLJS don't mention :dynamic
. How did you come to the conclusion that it's needed?
https://clojure.atlassian.net/browse/CLJS-1623?focusedCommentId=46238 David Nolen’s comment on this issue
Created https://ask.clojure.org/index.php/12766/docstring-redefs-should-mention-usage-dynamic-production
Ok here’s a new one for me: I load a page that should display content, check the subscription and it has content post-page load, but the DOM does not show it, however if I hot reload any code, the subscription updates.
Make sure you're not falling for the "rookie mistake" described in this section: https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md#form-2--a-function-returning-a-function
@U2FRKM4TW a-HA, I just changed a form 1 to form 2!