Fork me on GitHub

@aaelony did you include [ "0.5.1"]in your production devs?


They’re in the template to be added, but mustn’t be being added


Or maybe the uberjar isn’t using that profile


@aaelony Sorry, I meant dependencies and not devs.


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


@al.vyguzov just 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


probably a typo, hard to tell without 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


I’m just thinking, I thought I needed to


have the functions, etc setup


these are level 3 subs


So basically in my DSL this:

                   [:calc/subtract [:sf425/cash-received :sf425/cash-disbursed]]]
becomes this:
    [___51800__auto__ ___51800__auto__]
    [(re-frame.core/subscribe [:form/cur-field :sf425/cash-received])
     (re-frame.core/subscribe [:form/cur-field :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


I read about that problem at re-frame doc, but I forget where exactly :((

👍 4

ill poke around in there


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 [ "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. Many thanks


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.


or should i just be setting the initial db to a map of what i expect to be returned?


@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 that was the tactic i was going to take but then my app wouldn’t render


@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 that might help


i haven’t yet thank you


@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


 (fn [db [_ new-weather-data]]
   (assoc db/default-db :weather-data new-weather-data)))


When is it resetting back to the default value?


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 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 ( 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 (and I can answer questions if some part of that video is unclear)


awesome thank you, ill give this a watch too


im sure i’m just missing some little nuance


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 - when I can't use their components the patterns are really helpful to steal from 🙂


oh cool thnank you


i actually did spin up a fresh project and think i solved my issue and came up with a better approach


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.


@chadhs this project has an appraoch for more complex initial state setup

👍 4

@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


this was very helpful


fyi; think im good to go now

👍 4

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)
     (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
  (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
  (let [calc-fields (set (map first calcs))]
     (doseq  [calc calcs] (gen-calc-sub calc-fields calc))))


hi @eoliphant glad you got it working! 🙂