diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index f658645..24a74d8 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -204,7 +204,7 @@ (deftype Reaction [f ^:mutable state ^:mutable dirty? ^:mutable active? ^:mutable watching ^:mutable watches - ^:mutable auto-run on-set on-dispose] + auto-run on-set on-dispose ^:mutable norun?] IAtom IReactiveAtom @@ -251,7 +251,7 @@ (set! dirty? (max dirty? (if (identical? oldval newval) maybe-dirty is-dirty))) - (if auto-run + (if (and auto-run (not norun?)) (do ;; FIXME: is this correct? (when (== dirty? maybe-dirty) @@ -259,7 +259,8 @@ (-check-clean this))) (when-not (== dirty? clean) ((or auto-run run) this))) - (-notify-watches this state state)))) + (when (== old-dirty clean) + (-notify-watches this state state))))) ;; (when (and active? (not (identical? oldval newval))) ;; (set! dirty? is-dirty) ;; ((or auto-run run) this)) @@ -282,16 +283,16 @@ (-check-clean [this] (when (== dirty? maybe-dirty) - (let [oldauto auto-run] - (set! auto-run nil) - (doseq [w watching] - (-deref w)) - (set! auto-run oldauto)) + (set! norun? true) + (doseq [w watching] + (-deref w)) + (set! norun? false) (when (== dirty? maybe-dirty) (set! dirty? clean)))) IRunnable (run [this] + (set! norun? true) (let [oldstate state res (capture-derefed f this) derefed (captured this)] @@ -300,6 +301,7 @@ (when-not active? (when debug (swap! -running inc)) (set! active? true)) + (set! norun? false) (set! dirty? clean) (set! state res) (-notify-watches this oldstate state) @@ -353,7 +355,7 @@ dirty (if (not active) is-dirty clean) reaction (Reaction. f nil dirty active nil nil - runner on-set on-dispose)] + runner on-set on-dispose false)] (when-not (nil? derefed) (when debug (swap! -running inc)) (-update-watching reaction derefed)) diff --git a/test/reagenttest/testcursor.cljs b/test/reagenttest/testcursor.cljs index 5c08736..ac73d31 100644 --- a/test/reagenttest/testcursor.cljs +++ b/test/reagenttest/testcursor.cljs @@ -31,7 +31,7 @@ (is (= @out 2)) (reset! start 1) (is (= @out 3)) - (is (= @count 4)) + (is (= @count 2)) (dispose const) (is (= @start-base {:a {:b {:c 1}}})) (is (= (running) runs)))) diff --git a/test/reagenttest/testratom.cljs b/test/reagenttest/testratom.cljs index 0f91a40..8df5eb2 100644 --- a/test/reagenttest/testratom.cljs +++ b/test/reagenttest/testratom.cljs @@ -42,7 +42,7 @@ (is (= @out 2)) (reset! start 1) (is (= @out 3)) - (is (= @count 4)) + (is (= @count 2)) (dispose const) (is (= (running) runs)))) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 45d3d66..d7d94d9 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -122,13 +122,13 @@ (is (= 1 @ran)) (r/flush) (is (found-in #"val 1" div)) - (is (= 2 @ran)) + (is (= 2 @ran) "ran once more") ;; should not be rendered (reset! val 1) (r/flush) (is (found-in #"val 1" div)) - (is (= 2 @ran)))) + (is (= 2 @ran) "did not run"))) (is (= runs (running))) (is (= 2 @ran)))))