mirror of https://github.com/status-im/reagent.git
Revert experiment with lazy reaction
Needs more surgery to get this to work properly
This commit is contained in:
parent
d39656624d
commit
c862792624
|
@ -215,8 +215,7 @@
|
|||
(when on-set
|
||||
(set! dirty? true)
|
||||
(on-set oldval newval))
|
||||
(when (not (identical? oldval newval))
|
||||
(-notify-watches a oldval newval))
|
||||
(-notify-watches a oldval newval)
|
||||
newval))
|
||||
|
||||
ISwap
|
||||
|
@ -231,13 +230,9 @@
|
|||
|
||||
IComputedImpl
|
||||
(-handle-change [this sender oldval newval]
|
||||
(when (and active? (not dirty?)
|
||||
(or (instance? Reaction sender)
|
||||
(not (identical? oldval newval))))
|
||||
(when (and active? (not dirty?) (not (identical? oldval newval)))
|
||||
(set! dirty? true)
|
||||
(if auto-run
|
||||
((or auto-run run) this)
|
||||
(-notify-watches this state state))))
|
||||
((or auto-run run) this)))
|
||||
|
||||
(-update-watching [this derefed]
|
||||
(doseq [w derefed]
|
||||
|
@ -260,8 +255,7 @@
|
|||
(set! active? true))
|
||||
(set! dirty? false)
|
||||
(set! state res)
|
||||
(when (not (identical? oldstate state))
|
||||
(-notify-watches this oldstate state))
|
||||
(-notify-watches this oldstate state)
|
||||
res))
|
||||
|
||||
IDeref
|
||||
|
|
|
@ -50,10 +50,9 @@
|
|||
(is (= @c3 1))
|
||||
(is (= @c3-count 1) "t1")
|
||||
(swap! start inc)
|
||||
;; ought to be 2, ideally
|
||||
(is (= @c3-count 3) "t2")
|
||||
(is (= @c3-count 2) "t2")
|
||||
(is (= @c3 2))
|
||||
(is (= @c3-count 3) "t3")
|
||||
(is (= @c3-count 2) "t3")
|
||||
(is (= @start-base {:a {:b {:c 1}}}))
|
||||
(dispose c3)
|
||||
(is (= (running) runs))))
|
||||
|
@ -121,14 +120,13 @@
|
|||
(reset! a 3)
|
||||
(is (= @res (+ 10 @a)))
|
||||
(is (<= 2 @b-changed 3))
|
||||
;; Should be 2, ideally?
|
||||
(is (<= 2 @c-changed 3))
|
||||
(is (= @c-changed 2))
|
||||
(is (= @a-base {:test {:unsubscribe 3 :value 42}}))
|
||||
|
||||
(reset! a 3)
|
||||
(is (= @res (+ 10 @a)))
|
||||
(is (<= 2 @b-changed 3))
|
||||
(is (<= 2 @c-changed 3))
|
||||
(is (= @c-changed 2))
|
||||
(is (= @a-base {:test {:unsubscribe 3 :value 42}}))
|
||||
|
||||
(reset! a -1)
|
||||
|
|
|
@ -50,21 +50,18 @@
|
|||
c3-count (rv/atom 0)
|
||||
c1 (reaction @start 1)
|
||||
c2 (reaction @start)
|
||||
c2' (reaction
|
||||
(swap! c3-count inc)
|
||||
(+ @c1 @c2))
|
||||
c3 (rv/make-reaction
|
||||
(fn [] @c2')
|
||||
(fn []
|
||||
(swap! c3-count inc)
|
||||
(+ @c1 @c2))
|
||||
:auto-run true)]
|
||||
(is (= @c3-count 0))
|
||||
(is (= @c3 1))
|
||||
(is (= @c3-count 1) "t1")
|
||||
(swap! start inc)
|
||||
;; this ought to be 2, but probably not worth the
|
||||
;; trouble optimizing for
|
||||
(is (= @c3-count 3) "t2")
|
||||
(is (= @c3-count 2) "t2")
|
||||
(is (= @c3 2))
|
||||
(is (= @c3-count 3) "t3")
|
||||
(is (= @c3-count 2) "t3")
|
||||
(dispose c3)
|
||||
(is (= (running) runs))))
|
||||
|
||||
|
@ -124,13 +121,12 @@
|
|||
(reset! a 3)
|
||||
(is (= @res (+ 10 @a)))
|
||||
(is (<= 2 @b-changed 3))
|
||||
;; ought to be 2, ideally
|
||||
(is (<= 2 @c-changed 3))
|
||||
(is (= @c-changed 2))
|
||||
|
||||
(reset! a 3)
|
||||
(is (= @res (+ 10 @a)))
|
||||
(is (<= 2 @b-changed 3))
|
||||
(is (<= 2 @c-changed 3))
|
||||
(is (= @c-changed 2))
|
||||
|
||||
(reset! a -1)
|
||||
(is (= @res (+ 2 @a)))
|
||||
|
@ -242,15 +238,15 @@
|
|||
(is (= @b 6))
|
||||
(is (= runs (running)))))
|
||||
|
||||
(deftest catching
|
||||
(let [runs (running)
|
||||
a (rv/atom false)
|
||||
catch-count (atom 0)
|
||||
b (reaction (if @a (throw {})))
|
||||
c (run! (try @b (catch js/Object e
|
||||
(swap! catch-count inc))))]
|
||||
(is (= @catch-count 0))
|
||||
(reset! a false)
|
||||
(is (= @catch-count 0))
|
||||
(reset! a true)
|
||||
(is (= @catch-count 1))))
|
||||
;; (deftest catching
|
||||
;; (let [runs (running)
|
||||
;; a (rv/atom false)
|
||||
;; catch-count (atom 0)
|
||||
;; b (reaction (if @a (throw {})))
|
||||
;; c (run! (try @b (catch js/Object e
|
||||
;; (swap! catch-count inc))))]
|
||||
;; (is (= @catch-count 0))
|
||||
;; (reset! a false)
|
||||
;; (is (= @catch-count 0))
|
||||
;; (reset! a true)
|
||||
;; (is (= @catch-count 1))))
|
||||
|
|
|
@ -173,3 +173,25 @@
|
|||
(r/flush)
|
||||
(is (found-in #"value:4:" div))
|
||||
(is (= @ran 7)))))))
|
||||
|
||||
(deftest test-cursor
|
||||
(let [state (atom {:a 0
|
||||
:b 0})
|
||||
a-count (atom 0)
|
||||
b-count (atom 0)
|
||||
derefer (fn derefer [cur count]
|
||||
(swap! count inc)
|
||||
[:div @cur])
|
||||
comp (fn test-cursor []
|
||||
[:div
|
||||
[derefer (r/cursor state [:a]) a-count]
|
||||
[derefer (r/cursor state [:b]) b-count]])]
|
||||
(with-mounted-component [comp]
|
||||
(fn [c div]
|
||||
(is (= @a-count 1))
|
||||
(is (= @b-count 1))
|
||||
|
||||
(swap! state update-in [:a] inc)
|
||||
(r/flush)
|
||||
(is (= @a-count 2))
|
||||
(is (= @b-count 1))))))
|
||||
|
|
Loading…
Reference in New Issue