Fork me on GitHub
#reagent
<
2017-12-06
>
kennytilton00:12:44

Been playing with Reagent for the first time checking out its reactive behavior and I am wondering if I am missing something. Or maybe my expectations are off. I created an artificial chain of reactions to assess “glitch” avoidance, but there seems to be no risk of that because reactions do not cache calculations; they always recalculate and recursively so so no glitches can arise (but calculations are repeated):

kennytilton00:12:32

`(let [x (atom 0)
        ast (atom {:foo {:bar 1000
                         :baz 100}})
        abar (reagent/cursor ast [:foo :bar])
        abaz (reagent/cursor ast [:foo :baz])

        a (reagent/track
            (fn []
              (println :calc-aaa )
              (+ @abar (* 10 @x)))
            42)
        b (ra/make-reaction
            (fn []
              (println :calc-b)
              (+ @a (* 2 @x))))
        z (ra/make-reaction
            (fn []
              (println :calc-z)
              (+ @b @a @x)))]
    (println :x @x :a @a :z @z)
    (println :bumping-x!!!!!)
    (swap! x inc)
    (println :x @x :a @a :z @z)

    (println :bumping-abaz!!!!!)
    (swap! abaz inc)
    (println :x @x :a @a :z @z)
    )
`

kennytilton00:12:50

In the second bumping I targeted a cursor not in any calculation, but the whole chain of recalculations ran anyway. Am I doing this wrong or is Reagent not meant to be abused this way? 🙂

kennytilton01:12:36

I should mention that my first concern is that, since there are two paths back to “a” I see “calc-aaa” twice at each bump, and the second concern is that I see a full chain of calculations on the second bump.

worlds-endless19:12:54

When I use a vector for my {:class} of an object, the results are an invalid comma-separated string as the class of the div/object. Is this a bug, or a version thing?

mikerod19:12:48

@worlds-endless I thought it just had to be a string?

[:div {:class "first second"} ]

mikerod19:12:00

If there is support for vector conversion, I’m not aware of it

worlds-endless19:12:18

The front page says it's there "The :class attribute can accept either a collection or a string." https://github.com/reagent-project/reagent

mikerod19:12:48

you win then

mikerod19:12:56

Not sure what is the issue above in that case