Optimize track! and with-let a bit

This commit is contained in:
Dan Holmsand 2015-09-23 20:14:29 +02:00
parent e1585f6730
commit d476222abb
2 changed files with 11 additions and 16 deletions

View File

@ -29,10 +29,13 @@
(if (and (list? fin) (if (and (list? fin)
(= 'finally (first fin))) (= 'finally (first fin)))
[(butlast body) `(fn [] ~@(rest fin))] [(butlast body) `(fn [] ~@(rest fin))]
[body nil]))] [body nil]))
`(let [destroy-obj# (cljs.core/js-obj) 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#)] ~v (reagent.ratom/get-cached-values (quote ~v) destroy-obj#)]
(when *assert* (when ~asserting
(when-some [c# reagent.ratom/*ratom-context*] (when-some [c# reagent.ratom/*ratom-context*]
(when (== (.-ratomGeneration c#) (when (== (.-ratomGeneration c#)
(.-generation ~v)) (.-generation ~v))
@ -43,16 +46,8 @@
(let ~bs (let ~bs
(let [destroy# ~destroy (let [destroy# ~destroy
res# (do ~@forms)] res# (do ~@forms)]
(when-not (nil? destroy#)
(if (reagent.ratom/reactive?) (if (reagent.ratom/reactive?)
(set! (.-destroy destroy-obj#) destroy#) (set! (.-destroy destroy-obj#) destroy#)
(when (some? destroy#)
(destroy#))) (destroy#)))
res#))))) res#)))))

View File

@ -6,7 +6,7 @@
(declare ^:dynamic *ratom-context*) (declare ^:dynamic *ratom-context*)
(defn reactive? [] (defn ^boolean reactive? []
(some? *ratom-context*)) (some? *ratom-context*))
(defonce ^boolean debug false) (defonce ^boolean debug false)
@ -168,7 +168,7 @@
(Track. #(apply f args) [f args] nil)) (Track. #(apply f args) [f args] nil))
(defn track! [f & args] (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)] :auto-run :async)]
@r @r
r)) r))