Fork me on GitHub
#re-frame
<
2016-11-22
>
hwk01:11:17

1. I'm using reframe + reagent. 2. My code is (def main-panel [:div "hello world" [:pre "abc"] (fn [] [:pre "def"])]) 3. What happens is: "hello world" and "abc" renders "def" does not render 4. My question: why does "def" not render? I thought (fn [] ... ) were supposed to be auto-called -- as they are the parts that get recomputed when a reactive-atom changes.

geoffs02:11:33

@hwk My guess would be because it's not the first element in a vector. Try just wrapping it in []

mikethompson02:11:26

@hwk what @geoffs says is right. To understand why, you should read through the reagent tutorials at the bottom of this page: https://github.com/Day8/re-frame/wiki

hwk02:11:03

@geoffs: that worked, thanks! @mikethompson : will work through that -- earlier I worked through https://reagent-project.github.io/ -- and am now surprised this is documented under "re-frame" unstead of "reagent"

hwk02:11:54

https://github.com/Day8/re-frame/wiki/Creating%20Reagent%20Components <-- docs here is excellent. When I had to get canvas to work inside reagent -- this was the only page on the net that explaiend "form 3" and how to get canvas working.

hwk03:11:26

[:ul ~@(for [k lst] [:li (str k)])] <-- is it okay to do something like this, or will ~@ do something that bites me later ?

mikethompson03:11:48

I'd suggest (into [:ul] (for [k lst] [:li (str k)]))

hwk03:11:17

@mikethompson : clever use of (into) -- thanks!

vikeri07:11:56

@danielcompton @sam.roberton Great! I’ll mess around with it and when you’re starting documentation I might be able to chip in.

borkdude16:11:18

How to solve this problem: We have a local ratom for performance that takes the initial value of a subscription and we update it in our component. But whenever the subscription changes, the local ratom should also be updated.

borkdude16:11:41

maybe using a Reagent reaction?

borkdude16:11:16

add-watch...

mikethompson20:11:13

@borkdude no clean way to do that that I'm aware of

mikethompson20:11:17

In the absence of "clean", it comes down to "simple". Perhaps: (reaction (reset! local-ratom @sub) )

mikethompson20:11:41

So

(defn view 
   []
   (let [sub  (subscribe [:some :thing])
         rat  (reagent/atom 12)
         _    (reaction (reset! rat @sub))]
    (fn view-render
       []   
       [:div ....])))
When the value delivered by sub changes, rat will be reset! to that new value.