Clojurians
#reagent
<
2016-01-23
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

mpdairy00:01:20

Does anyone know when on-dispose gets called in make-reaction?

eggsyntax00:01:40

@mpdairy: "A Reaction will dispose of itself when the number of watches (things derefing it) transitions from 1 to 0.” I haven’t done anything with on-dispose myself, but maybe that’s helpful? https://github.com/Day8/re-frame/issues/29

mpdairy01:01:41

So I am dereferencing the test reaction inside of a component named ratom-test that is called inside another component like this (when (= @rtoggle 1) [ratom-test])

mpdairy01:01:02

I have a button that changes the rtoggle atom to 0, after which the [ratom-test] component disappears. Shouldn't that then dispose the reaction that I derefed in the ratom-test component?

gadfly36107:01:58

Really digging petrol by @krisajenkins https://github.com/krisajenkins/petrol

mpdairy20:01:47

Ok I got :on-dispose working. It worked when I tried it on the real thing, though it didn't work for some reason on my test setup.

mpdairy21:01:07

I am wondering about Reagent's re-rendering here:

mpdairy21:01:14

(def toggle (r/atom 1))

(defn compo [n]
  (println "compo: " n)
  [:div n])

(defn test-app []
  [:div
   (when (= @toggle 1) [compo 5])
   [compo 1]
   [compo 2]
   [compo 3]
   [compo 4]
   [:button
    {:on-click (fn [] (swap! toggle #(if (= % 1) 0 1)))}
    "Toggle"]])

mpdairy21:01:47

When I click on the "Toggle" button, it re-renders compo 1-4 every time and 5 every other time. However, if I move (when (= @toggle 1) [compo 5]) down to the bottom, it doesn't re-render any of the other compos.

mpdairy21:01:29

It seems like it shouldn't have to re-render any of the later sibling elements just because one gets deleted.

mikethompson23:01:15

Put a key on the components, so that React knows which is which: ^{:key "1"}[compo 1] ^{:key "2"}[compo 2] etc

mikethompson23:01:00

At the moment, when the first component disappears, (or reappears) React doesn't have enough information to know that there's been a shuffle up or down. So it just rerenders all. Once you give keys, you are giving it more information, and it can avoid the unnecessary rerender.

potapenko23:01:44

(defn test-app []
  (fn[]
    [:div
     (when (= @toggle 1) [compo 5])
     [compo 1]
     [compo 2]
     [compo 3]
     [compo 4]
     [:button
      {:on-click (fn [] (swap! toggle #(if (= % 1) 0 1)))}
      "Toggle"]]))