mirror of
https://github.com/status-im/reagent.git
synced 2025-01-14 13:54:08 +00:00
Allow deref of Reaction outside active Reaction
This commit is contained in:
parent
99cc5ef506
commit
0e7f5518c0
@ -105,14 +105,15 @@
|
|||||||
(= ratom (.-ratom other))
|
(= ratom (.-ratom other))
|
||||||
(= setf (.-setf other))))
|
(= setf (.-setf other))))
|
||||||
|
|
||||||
|
Object
|
||||||
|
(_reaction [this]
|
||||||
|
(if (nil? reaction)
|
||||||
|
(set! reaction (make-reaction #(get-in @ratom path)))
|
||||||
|
reaction))
|
||||||
|
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [this]
|
(-deref [this]
|
||||||
(if (nil? *ratom-context*)
|
(deref (._reaction this)))
|
||||||
(get-in @ratom path)
|
|
||||||
(do
|
|
||||||
(if (nil? reaction)
|
|
||||||
(set! reaction (make-reaction #(get-in @ratom path))))
|
|
||||||
@reaction)))
|
|
||||||
|
|
||||||
IReset
|
IReset
|
||||||
(-reset! [a new-value]
|
(-reset! [a new-value]
|
||||||
@ -244,15 +245,15 @@
|
|||||||
|
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [this]
|
(-deref [this]
|
||||||
;; TODO: relax this?
|
(if-not (or auto-run *ratom-context*)
|
||||||
(when (not (or auto-run *ratom-context*))
|
(if dirty?
|
||||||
(dbg [auto-run *ratom-context*]))
|
(set! state (f))
|
||||||
(assert (or auto-run *ratom-context*)
|
state)
|
||||||
"Reaction derefed outside auto-running context")
|
(do
|
||||||
(notify-deref-watcher! this)
|
(notify-deref-watcher! this)
|
||||||
(if dirty?
|
(if dirty?
|
||||||
(run this)
|
(run this)
|
||||||
state))
|
state))))
|
||||||
|
|
||||||
IDisposable
|
IDisposable
|
||||||
(dispose! [this]
|
(dispose! [this]
|
||||||
|
@ -229,3 +229,13 @@
|
|||||||
(dispose b)
|
(dispose b)
|
||||||
(is (= runs (running)))))
|
(is (= runs (running)))))
|
||||||
|
|
||||||
|
(deftest non-reactive-deref
|
||||||
|
(let [runs (running)
|
||||||
|
a (rv/atom 0)
|
||||||
|
b (rv/make-reaction #(+ 5 @a))]
|
||||||
|
(is (= @b 5))
|
||||||
|
(is (= runs (running)))
|
||||||
|
|
||||||
|
(reset! a 1)
|
||||||
|
(is (= @b 6))
|
||||||
|
(is (= runs (running)))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user