From d476222abbf58d805b454f757aa9bf060ce1d3c1 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Wed, 23 Sep 2015 20:14:29 +0200 Subject: [PATCH] Optimize track! and with-let a bit --- src/reagent/ratom.clj | 23 +++++++++-------------- src/reagent/ratom.cljs | 4 ++-- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/reagent/ratom.clj b/src/reagent/ratom.clj index 3769a0e..b4b988b 100644 --- a/src/reagent/ratom.clj +++ b/src/reagent/ratom.clj @@ -29,10 +29,13 @@ (if (and (list? fin) (= 'finally (first fin))) [(butlast body) `(fn [] ~@(rest fin))] - [body nil]))] - `(let [destroy-obj# (cljs.core/js-obj) + [body nil])) + destroy-obj (when destroy + `(cljs.core/js-obj)) + asserting (if *assert* true false)] + `(let [destroy-obj# ~destroy-obj ~v (reagent.ratom/get-cached-values (quote ~v) destroy-obj#)] - (when *assert* + (when ~asserting (when-some [c# reagent.ratom/*ratom-context*] (when (== (.-ratomGeneration c#) (.-generation ~v)) @@ -43,16 +46,8 @@ (let ~bs (let [destroy# ~destroy res# (do ~@forms)] - (if (reagent.ratom/reactive?) - (set! (.-destroy destroy-obj#) destroy#) - (when (some? destroy#) + (when-not (nil? destroy#) + (if (reagent.ratom/reactive?) + (set! (.-destroy destroy-obj#) destroy#) (destroy#))) res#))))) - - - - - - - - diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 528d5e9..2d72f23 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -6,7 +6,7 @@ (declare ^:dynamic *ratom-context*) -(defn reactive? [] +(defn ^boolean reactive? [] (some? *ratom-context*)) (defonce ^boolean debug false) @@ -168,7 +168,7 @@ (Track. #(apply f args) [f args] nil)) (defn track! [f & args] - (let [r (make-reaction #(deref (apply track f args)) + (let [r (make-reaction #(-deref (apply track f args)) :auto-run :async)] @r r))