From 28d454ece9e400de6e2479d9c4c81cb400286fed Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Thu, 24 Sep 2015 07:48:03 +0200 Subject: [PATCH] Include size of cached reactions in tests --- src/reagent/ratom.cljs | 7 ++++--- test/reagenttest/testcursor.cljs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 2d72f23..a0b0a47 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -5,6 +5,7 @@ [reagent.debug :refer-macros [dbg log warn dev?]])) (declare ^:dynamic *ratom-context*) +(defonce cached-reactions {}) (defn ^boolean reactive? [] (some? *ratom-context*)) @@ -15,7 +16,9 @@ (defonce -running (clojure.core/atom 0)) -(defn running [] @-running) +(defn running [] + (+ @-running + (count cached-reactions))) (defn capture-derefed [f obj] (set! (.-cljsCaptured obj) nil) @@ -118,8 +121,6 @@ (declare make-reaction) -(defonce cached-reactions {}) - (defn- cached-reaction [f key obj destroy] (if-some [r (get cached-reactions key)] (-deref r) diff --git a/test/reagenttest/testcursor.cljs b/test/reagenttest/testcursor.cljs index dbe6006..0453266 100644 --- a/test/reagenttest/testcursor.cljs +++ b/test/reagenttest/testcursor.cljs @@ -193,19 +193,19 @@ :on-dispose #(reset! disposed-cns true))] @cns (is (= @res 2)) - (is (= (+ 5 runs) (running))) + (is (= (+ 6 runs) (running))) (is (= @count-b 1)) (is (= {:a 0 :b 0} @a-base)) (reset! a -1) (is (= @res 1)) (is (= @disposed nil)) (is (= @count-b 2)) - (is (= (+ 5 runs) (running)) "still running") + (is (= (+ 6 runs) (running)) "still running") (is (= {:a -1 :b 0} @a-base)) (reset! a 2) (is (= @res 1)) (is (= @disposed true)) - (is (= (+ 3 runs) (running)) "less running count") + (is (= (+ 4 runs) (running)) "less running count") (is (= {:a 2 :b 0} @a-base)) (reset! disposed nil)