This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-20
Channels
- # announcements (1)
- # babashka (74)
- # beginners (84)
- # bristol-clojurians (3)
- # cider (2)
- # clara (14)
- # cljdoc (18)
- # cljsrn (7)
- # clojure (29)
- # clojure-australia (4)
- # clojure-europe (34)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-seattle (1)
- # clojure-uk (33)
- # clojuredesign-podcast (2)
- # clojurescript (33)
- # code-reviews (17)
- # core-async (10)
- # cursive (8)
- # datomic (21)
- # depstar (45)
- # dirac (4)
- # duct (10)
- # emacs (1)
- # fulcro (8)
- # jackdaw (2)
- # jobs (1)
- # kaocha (11)
- # leiningen (2)
- # off-topic (8)
- # pathom (35)
- # pedestal (3)
- # protorepl (13)
- # rdf (39)
- # re-frame (23)
- # reagent (2)
- # releases (1)
- # remote-jobs (6)
- # reveal (2)
- # rewrite-clj (18)
- # shadow-cljs (51)
- # sim-testing (2)
- # spacemacs (2)
- # tools-deps (37)
Hello all. Let me ask something quick: I'm having a problem with my subscriptions. Somehow, my subscriptions only worked when i reload the page (i go to the page, back to the previous page and then the data is loaded). Have someone pass through this before? i'm using the 1.0.0-alpha.2 version of reagent with a custom compiler with the function-components option set to true. I don't know if this interfere in something
The problem definition is very vague. What does "subscription is not working" mean? What does "the data is loaded" mean?
Sorry, let me explain better
I have an event that is dispatched when i click into a link and get's data from a service and show another page. In this another page, i have a subscription to get that data and fill the components with data.
What happens is that the data is not being showed at ti first time. I had to go back to the previous page and then click again so the data is showed in the componentes
I'm afraid these additional details have only muddled the water. :) There are too many moving parts and even more vagueness now. Can you create a minimal reproducible example?
I'll try
Another example is: i fill a select with data from a subscription. The data is showed in the select only when i back to the previous page and load the page that contains the select again.
(defn policy-details
[]
(fn []
(let [policy-details (subscribe [::subs/policy-details])]
[policy-details-view @policy-details])))
(defn policy-details-view
[policy-details]
[theme {:color-primary "#e6ac00"}
[print-pdf]
[form {:namespace :policies:*:policy-details:show
:class-name (:container style)}
[page-title {:icon [pdf]
:label (str (:policy-name policy-details) " | " (:policy-number policy-details))}]
[:section {:id "policyheader"}
[:div {:class-name (:itempolicyheader style)}
[start-date]
[label nil " Start Date "]
[:b (:start-date policy-details)]]
[:div {:class-name (:itempolicyheader style)}
[end-date]
[label nil " End Date "]
[:b (:end-date policy-details)]]
[:div {:class-name (:itempolicyheader style)}
[calendar]
[label nil " Next Settlement "]
[:b (:next-settlement policy-details)]]]])
Nothing incriminating at all, except that you can remove the inner function in policy-details
. But it shouldn't change anything.
(defn policy-details
[]
(let [policy-details (subscribe [::subs/policy-details])]
[policy-details-view @policy-details]))
I don't know if the fact of using a custom compiler is responsible for it
Another example (reg-event-fx :policies:*:policy-selection:requested (fn [{:keys [db]} [_ & args]] (println ":policies:*:policy-selection:requested" args) {:db db :dispatch-n [[::customers/needed] [::agents/needed]]}))
(defn policy-selection
[]
(dispatch [:policies:*:policy-selection:requested])
(let [agents (subscribe [::agents/dropdown-options])
customers (subscribe [::customers/dropdown-options])
search-policies (fn [param value]
(dispatch [:policies-load param value]))
value-of (fn [key]
@(subscribe [::subs/attribute-value :policies:*:policy-selection:list key]))]
(fn []
[policy-selection-view {:agents @agents
:customers @customers
:action search-policies
:value value-of}])))
Don't use subscribe
in some callbacks that aren't called during the render phase, like view-of
might be.
But again, it shouldn't really affect anything, it's just a matter of potential memory leakage.
How would you code that value-of part? My intention is to avoid calling the same subscription with only one different parameter
It depends. If value-of
is called only during the rendering and not in run time when e.g. a user interacts with the component somehow, then your code is fine.
If it's for interactions, then you would have to subscribe to all the data that's required for :value
but that doesn't depend on key
and then create value-of
based on that data, so there no longer a call to subscribe
in value-of
.
We launched http://Pitch.com publicly today, front end is written with re-frame (over 125K lines of Clojure/ClojureScript all told) - thanks @mikethompson for making something that works so well at a large scale!

That's awesome to hear, seems the launch is going great so far, lots of love all over Twitter ❤️ Would be great to have a breakdown of what issues you hit with cljs/reagent/re-frame at that scale. Basically a development post-mortem 🙂
Good idea!
wow congratulations
looks great