mirror of https://github.com/status-im/reagent.git
Optimize track! and with-let a bit
This commit is contained in:
parent
e1585f6730
commit
d476222abb
|
@ -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)]
|
||||
(when-not (nil? destroy#)
|
||||
(if (reagent.ratom/reactive?)
|
||||
(set! (.-destroy destroy-obj#) destroy#)
|
||||
(when (some? destroy#)
|
||||
(destroy#)))
|
||||
res#)))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue