This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # architecture (6)
- # beginners (36)
- # boot (4)
- # cider (74)
- # cljsrn (5)
- # clojure (87)
- # clojure-denver (2)
- # clojure-finland (2)
- # clojure-gamedev (5)
- # clojure-italy (10)
- # clojure-nl (1)
- # clojure-uk (45)
- # clojurescript (33)
- # code-reviews (5)
- # core-async (12)
- # cursive (17)
- # datascript (2)
- # datomic (71)
- # duct (4)
- # emacs (19)
- # figwheel (1)
- # fulcro (4)
- # garden (1)
- # hoplon (18)
- # jobs (5)
- # leiningen (2)
- # off-topic (73)
- # onyx (14)
- # overtone (2)
- # portkey (32)
- # re-frame (62)
- # reagent (46)
- # shadow-cljs (76)
- # spacemacs (2)
- # sql (14)
- # tools-deps (5)
- # yada (3)
If different components require one (re-rfame/subscribe ...) what should to do pass it to components arguments or register it within each component separately?
I explore the todomvc example and notice that the components have not props. Does Re-frame suggest to avoid props in components?
@al.vyguzov: Not sure if I understand the question - are you trying to call the same component in different places so that they rely on different subscriptions to get the data they need?
No, the different components use the same subscription. This components put in each other hierarchically
And I try to realize what way is more right. Put this subscription to props or register it in different components separately
subscribe at each place where you need it... no need to pass around the sub reactions
Hi, does anyone have any idea why I might be getting a “no subscription handler registered for..” message for a subscription that, I’m 99% sure it’s reg-sub has been read in? I’ve required the namespace that contains the reg-sub in the namespace where the subscribe is. I’ve also played around with requiring it in the initial/core namespace just to be sure and still seeing the issue. i was also looking to see if there was any logging or something I could turn on that might help but i didn’t see any in the source
yeah I’ve verified that it’s not that 😞 it was working fine, It’s not even somethign I’ve changed. But I
I’ve been working on a macro that would dynamically create subs based on a DSL (basically to setup calculated fields on a form).. This was one of the basic ones that was inline in the code, so that makes it even weirder
I know it's not related to your current problem, but creating a macro to dynamically register subs is probably wrong in 2 ways
1) nothing prevents you from registering subs from a
defn (i.e. no macro needed)
2) subs take arbitrary arguments so you could use an argument instead of dynamically generated sub identifiers
hmm, ok i thought about that too. But then there was the thing of avoiding overly generic subs lol
So basically in my DSL this:
[:sf425/cash-on-hand [:calc/subtract [:sf425/cash-received :sf425/cash-disbursed]]]
The other complication is that in some cases I need to subscribe to another sub. So I have logic in a function to figure that out. But I thought I needed a macro to dynamically get everything setup properly, I can give it a whirl again
(re-frame.core/reg-sub :sf425/cash-on-hand (clojure.core/fn [___51800__auto__ ___51800__auto__] [(re-frame.core/subscribe [:form/cur-field :sf425/cash-received]) (re-frame.core/subscribe [:form/cur-field :sf425/cash-disbursed])]) (clojure.core/fn [args__51801__auto__] (fema-gmm.components.forms.calculations/run-calc :calc/subtract args__51801__auto__)))
Ok, it’s fixed but I have no idea why lol. There was something weird going on, in another component that caused an error unrelated to subscriptions, etc after the one I described. Yet fixing that fixed my issue
Hi @sveri, I can confirm that adding
[day8.re-frame/tracing-stubs "0.5.1"] to :dependencies does fix the issue of the lein uberjar failing to build. That should likely be added to the lein re-frame template as well.
what should you use for an initial db state for an item that is an api response? i’m not sure how to do this since cljs-ajax and cljs-http both use async calls.
@chadhs: I usually leave that part of my app-db either empty or with some default empty structure/value - as long as you populate it later with
assoc-in it doesn't seem to cause any issues
@U054BUGT4 when you say empty did you have the key with an empty value or not even in the db to begin with?
Pretty sure I have nothing in some of them - though my app-db isn't empty at the start
mine is pretty simple; initial db is current-time and an api response. but i can’t seem to escape the fact that i have to be in a go block to get that response.
If you haven't already, you could see if there's something in https://github.com/Day8/re-frame/blob/master/docs/Loading-Initial-Data.md that might help
@U054BUGT4 think i got this to work; the only odd behavior i notice now is the value will update and then flip back to the default; have you seen this
Does it change back to the default after you change your code (if figwheel hot-reloads your code for you)?
oh it’s a time based dispatch
(defonce do-weather (js/setInterval dispatch-weather-event 10000))
so it’s fetching weather data and updating the db ever 10 secs (for testing purposes, will be every 30 mins in future
(re-frame/reg-event-db ::weather (fn [db [_ new-weather-data]] (assoc db/default-db :weather-data new-weather-data)))
immediately, and i set a static value to change to just to isolate the issue and prove it wasn’t related to my http call
If you haven't done it yet, it may be worth adding https://github.com/Day8/re-frame-10x to your project to see if it can help you track down the problem. It's a bit overkill for a really small application but if you're planning on doing a decent amount of re-frame development in the future it's a pretty fantastic tool for understanding your application (https://github.com/flexsurfer/re-frisk is also very good and may fit better depending on what the future of your project looks like).
The other thing you might want to check is how your initial render / re-renders are working, it's possible those could be causing some of your problems. I'm sure there are docs that go into this, but I can't find them right now. I cover it near the beginning of https://youtu.be/cDzjlx6otCU (and I can answer questions if some part of that video is unclear)
Hopefully you can get it all working nicely - there are also some tricky bits to keeping things like textboxes in sync, so if you end up doing more complicate UI components a good resource is https://github.com/Day8/re-com - when I can't use their components the patterns are really helpful to steal from 🙂
i actually did spin up a fresh project and think i solved my issue and came up with a better approach
this was very helpful as well https://github.com/Day8/re-frame/blob/master/docs/Talking-To-Servers.md
That's great - the docs (and some of the examples and external resources) have a lot of really useful content. Feel free to bug me more as well and I'll help if I can.
@eoliphant thnx ill take a look; may take some study im pretty new to reagent / re-frame
Yeah, I love the two, really cool stuff. but I’ve found that while the basic concepts are pretty straightforward, a lot of little, yet common things (like ‘booting’ your SPA) aren’t always super clear. If you haven’t already, also check out the sample apps. I didn’t when I started (just blasted through the docs) and missed some key concepts/patterns
true and what im building is actually taking their clock sample and just adding weather data.
the odd behavior i’m seeing now is values reverting to the initial db state a second after updating
Hey @joelsanchez you were right, got it all working and no macro hell
#_(defn gen-calc-sub "Create the level 3 subscription. If the field is in calcs, it's a calculated field and we should directly subscribe to it, otherwise subscribe to the actual field value" [calcs [field [calc args]]] (print "creating sub for: " field) `(rf/reg-sub ~field (fn [_# _#] ~(mapv (fn [arg] (if (calcs arg) `(rf/subscribe [~arg]) `(rf/subscribe [:form/cur-field ~arg]))) args)) (fn [args#] (calc/run-calc ~calc args#)))) (defn gen-calc-sub [calc-fields [field [calc args]]] (let [level-2-func-vec (mapv (fn [arg] (if (calc-fields arg) (rf/subscribe [arg]) (rf/subscribe [:form/cur-field arg]))) args) level-2-func (fn [_ _] level-2-func-vec) level-3-func (fn [args] (calc/run-calc calc args))] (rf/reg-sub field level-2-func level-3-func))) #_(defmacro gen-calc-subs [calcs] (print "creating subs for: " calcs) (let [calc-fields (set (map first calcs)) ;for quick membership test ] `(do [email protected](map #(gen-calc-sub calc-fields %) calcs)))) (defn gen-calc-subs [calcs] (let [calc-fields (set (map first calcs))] (doseq [calc calcs] (gen-calc-sub calc-fields calc))))