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)
(= '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#)))))

View File

@ -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))