mirror of https://github.com/status-im/reagent.git
Make sure reactions continue to run after throw
This commit is contained in:
parent
8ff44c81e6
commit
9631021da7
|
@ -89,8 +89,9 @@
|
|||
(.flush-queues render-queue))
|
||||
|
||||
(defn queue-render [c]
|
||||
($! c :cljsIsDirty true)
|
||||
(.queue-render render-queue c))
|
||||
(when-not ($ c :cljsIsDirty)
|
||||
($! c :cljsIsDirty true)
|
||||
(.queue-render render-queue c)))
|
||||
|
||||
(defn mark-rendered [c]
|
||||
($! c :cljsIsDirty false))
|
||||
|
|
|
@ -374,9 +374,10 @@
|
|||
(_handle-change [this sender oldval newval]
|
||||
(when-not (or (identical? oldval newval)
|
||||
dirty?)
|
||||
(set! dirty? true)
|
||||
(if (nil? auto-run)
|
||||
(rea-enqueue this)
|
||||
(do
|
||||
(set! dirty? true)
|
||||
(rea-enqueue this))
|
||||
(if (true? auto-run)
|
||||
(._run this)
|
||||
(auto-run this)))))
|
||||
|
@ -395,8 +396,9 @@
|
|||
(try
|
||||
(._run this)
|
||||
(catch :default e
|
||||
(set! state nil)
|
||||
(set! state e)
|
||||
(set! caught e)
|
||||
(set! dirty? false)
|
||||
(notify-w this e nil)))))
|
||||
|
||||
(_run [this]
|
||||
|
|
|
@ -330,3 +330,43 @@
|
|||
(is (= (:derived @state) 33))
|
||||
(dispose rxn)
|
||||
(is (= runs (running)))))
|
||||
|
||||
(deftest exception-recover
|
||||
(let [runs (running)
|
||||
state (rv/atom 1)
|
||||
count (rv/atom 0)
|
||||
r (run!
|
||||
(swap! count inc)
|
||||
(when (> @state 1)
|
||||
(throw (js/Error. "oops"))))]
|
||||
(is (= @count 1))
|
||||
(is (thrown? :default (do
|
||||
(swap! state inc)
|
||||
(rv/flush!))))
|
||||
(is (= @count 2))
|
||||
(swap! state dec)
|
||||
(rv/flush!)
|
||||
(is (= @count 3))
|
||||
(dispose r)
|
||||
(is (= runs (running)))))
|
||||
|
||||
(deftest exception-recover-indirect
|
||||
(let [runs (running)
|
||||
state (rv/atom 1)
|
||||
count (rv/atom 0)
|
||||
ref (reaction
|
||||
(when (= @state 2)
|
||||
(throw (js/Error. "err"))))
|
||||
r (run!
|
||||
(swap! count inc)
|
||||
@ref)]
|
||||
(is (= @count 1))
|
||||
(is (thrown? :default (do
|
||||
(swap! state inc)
|
||||
(rv/flush!))))
|
||||
(is (= @count 2))
|
||||
(swap! state inc)
|
||||
(rv/flush!)
|
||||
(is (= @count 3))
|
||||
(dispose r)
|
||||
(is (= runs (running)))))
|
||||
|
|
Loading…
Reference in New Issue