Closed rgkirch closed 1 year ago
I expect that commenting out (r/dispose! click-count-tracker)
would fail the test but it doesn't. Needs work.
Does it work with the code outside of SCI?
I haven't tested that yet.
(ns sandbox.app
(:require [reagent.core :as r]
[reagent.dom :as rdom]))
(def click-count (r/atom 1))
(def integral (r/atom 0))
(def click-count-tracker (r/track! (fn integrate [] (swap! integral + @click-count))))
(defn counting-component []
[:div @integral])
(defn init []
(rdom/render [counting-component] (js/document.getElementById "app"))
(swap! click-count inc)
(r/dispose! click-count-tracker)
(swap! click-count inc))
gives 1
while
(ns sandbox.app
(:require [reagent.core :as r]
[reagent.dom :as rdom]))
(def click-count (r/atom 1))
(def integral (r/atom 0))
(def click-count-tracker (r/track! (fn integrate [] (swap! integral + @click-count))))
(defn counting-component []
[:div @integral])
(defn init []
(rdom/render [counting-component] (js/document.getElementById "app"))
(swap! click-count inc)
(swap! click-count inc))
gives 4
🤔
(ns sandbox.app
(:require [reagent.core :as r]
[reagent.dom :as rdom]))
(def click-count (r/atom 1))
(add-watch click-count (gensym) (fn [k r o n] (println "click-count: " n)))
(def integral (r/atom 0))
(add-watch integral (gensym) (fn [k r o n] (println "integral: " n)))
(def click-count-tracker (r/track! (fn integrate []
(println (str "(swap! integral + " @click-count ")"))
(swap! integral + @click-count))))
(defn counting-component []
[:div @integral])
(defn init []
(rdom/render [counting-component] (js/document.getElementById "app"))
(swap! click-count inc)
(r/dispose! click-count-tracker)
(swap! click-count inc))
(swap! integral + 1)
integral: 1
click-count: 2
click-count: 3
(ns sandbox.app
(:require [reagent.core :as r]
[reagent.dom :as rdom]))
(def click-count (r/atom 1))
(add-watch click-count (gensym) (fn [k r o n] (println "click-count: " n)))
(def integral (r/atom 0))
(add-watch integral (gensym) (fn [k r o n] (println "integral: " n)))
(def click-count-tracker (r/track! (fn integrate []
(println (str "(swap! integral + " @click-count ")"))
(swap! integral + @click-count))))
(defn counting-component []
[:div @integral])
(defn init []
(rdom/render [counting-component] (js/document.getElementById "app"))
(swap! click-count inc)
(swap! click-count inc))
(swap! integral + 1)
integral: 1
click-count: 2
click-count: 3
(swap! integral + 3)
integral: 4
Btw, I'm fine with just adding these functions. Since they are just functions, I don't see why they would behave differently inside SCI than outside SCI...
Ok. Should I just remove the test?
Fine with me
The test currently doesn't actually work.