mirror of https://github.com/status-im/reagent.git
Warn if the same with-kept is used more than once
This commit is contained in:
parent
6c9f71e511
commit
a73761e72e
|
@ -32,6 +32,14 @@
|
|||
[body nil]))]
|
||||
`(let [destroy-obj# (cljs.core/js-obj)
|
||||
~v (reagent.ratom/get-cached-values (quote ~v) destroy-obj#)]
|
||||
(when *assert*
|
||||
(when-some [c# reagent.ratom/*ratom-context*]
|
||||
(when (== (.-ratomGeneration c#)
|
||||
(.-generation ~v))
|
||||
(js/console.error
|
||||
"The same with-kept is being used more than once in the
|
||||
same reactive context."))
|
||||
(set! (.-generation ~v) (.-ratomGeneration c#))))
|
||||
(let ~bs
|
||||
(let [destroy# ~destroy
|
||||
res# (do ~@forms)]
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
(defonce ^boolean debug false)
|
||||
(defonce ^boolean silent false)
|
||||
(defonce generation 0)
|
||||
|
||||
(defonce -running (clojure.core/atom 0))
|
||||
|
||||
|
@ -18,6 +19,9 @@
|
|||
|
||||
(defn capture-derefed [f obj]
|
||||
(set! (.-cljsCaptured obj) nil)
|
||||
(when (dev?)
|
||||
(set! (.-ratomGeneration obj)
|
||||
(set! generation (inc generation))))
|
||||
(binding [*ratom-context* obj]
|
||||
(f)))
|
||||
|
||||
|
@ -500,6 +504,9 @@
|
|||
(when-not (nil? derefed)
|
||||
(warn "using derefed is deprecated"))
|
||||
(when-not (nil? derefs)
|
||||
(when (dev?)
|
||||
(set! (.-ratomGeneration reaction)
|
||||
(.-ratomGeneration derefs)))
|
||||
(-update-watching reaction derefs))
|
||||
reaction))
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
(is (= (running) runs))))
|
||||
|
||||
(deftest test-track!
|
||||
(sync)
|
||||
(let [runs (running)
|
||||
start (rv/atom 0)
|
||||
svf (fn [] @start)
|
||||
|
|
Loading…
Reference in New Issue