From 679136f5d542d7141f6598108fa5769245bff822 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Fri, 11 Sep 2015 12:35:06 +0200 Subject: [PATCH] Make constants const --- project.clj | 2 +- src/reagent/ratom.cljs | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/project.clj b/project.clj index b73eca9..2c78928 100644 --- a/project.clj +++ b/project.clj @@ -47,7 +47,7 @@ {:compiler {:optimizations :advanced :elide-asserts true :pretty-print false - :pseudo-names true + ;; :pseudo-names true :output-dir "target/client"}}}}}] :prod-test [:test :prod] diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 463fac1..b986a70 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -202,9 +202,9 @@ (-handle-change [this sender oldval newval]) (-update-watching [this derefed])) -(def clean 0) -(def maybe-dirty 1) -(def dirty 2) +(def ^:const clean 0) +(def ^:const maybe-dirty 1) +(def ^:const dirty 2) (deftype Reaction [f ^:mutable state ^:mutable ^number dirtyness ^:mutable watching ^:mutable watches @@ -326,7 +326,7 @@ (set! watching nil) (set! state nil) (set! dirtyness dirty) - (when on-dispose + (when (some? on-dispose) (on-dispose))) IEquiv @@ -419,3 +419,24 @@ (util/partial-ifn. callback-fn args nil) false nil)) +(comment + (def perf-check 0) + (defn ratom-perf [] + (dbg "ratom-perf") + (set! debug false) + (dotimes [_ 10] + (set! perf-check 0) + (let [nite 100000 + a (atom 0) + mid (make-reaction (fn [] (inc @a))) + res (make-reaction (fn [] + (set! perf-check (inc perf-check)) + (inc @mid)) + :auto-run true)] + @res + (time (dotimes [x nite] + (swap! a inc))) + (dispose! res) + (assert (= perf-check (inc nite)))))) + (enable-console-print!) + (ratom-perf))