mirror of https://github.com/status-im/reagent.git
Start switch to three-state dirty status
This commit is contained in:
parent
b77b182d67
commit
829be2efa1
|
@ -197,6 +197,10 @@
|
||||||
(-handle-change [k sender oldval newval])
|
(-handle-change [k sender oldval newval])
|
||||||
(-peek-at [this]))
|
(-peek-at [this]))
|
||||||
|
|
||||||
|
(def clean 0)
|
||||||
|
(def maybe-dirty 1)
|
||||||
|
(def is-dirty 2)
|
||||||
|
|
||||||
(deftype Reaction [f ^:mutable state ^:mutable dirty? ^:mutable active?
|
(deftype Reaction [f ^:mutable state ^:mutable dirty? ^:mutable active?
|
||||||
^:mutable watching ^:mutable watches
|
^:mutable watching ^:mutable watches
|
||||||
auto-run on-set on-dispose]
|
auto-run on-set on-dispose]
|
||||||
|
@ -224,7 +228,7 @@
|
||||||
(let [oldval state]
|
(let [oldval state]
|
||||||
(set! state newval)
|
(set! state newval)
|
||||||
(when on-set
|
(when on-set
|
||||||
(set! dirty? true)
|
(set! dirty? is-dirty)
|
||||||
(on-set oldval newval))
|
(on-set oldval newval))
|
||||||
(-notify-watches a oldval newval)
|
(-notify-watches a oldval newval)
|
||||||
newval))
|
newval))
|
||||||
|
@ -242,7 +246,7 @@
|
||||||
IComputedImpl
|
IComputedImpl
|
||||||
(-handle-change [this sender oldval newval]
|
(-handle-change [this sender oldval newval]
|
||||||
(when (and active? (not (identical? oldval newval)))
|
(when (and active? (not (identical? oldval newval)))
|
||||||
(set! dirty? true)
|
(set! dirty? is-dirty)
|
||||||
((or auto-run run) this)))
|
((or auto-run run) this)))
|
||||||
|
|
||||||
(-update-watching [this derefed]
|
(-update-watching [this derefed]
|
||||||
|
@ -255,7 +259,7 @@
|
||||||
(set! watching derefed))
|
(set! watching derefed))
|
||||||
|
|
||||||
(-peek-at [this]
|
(-peek-at [this]
|
||||||
(if-not dirty?
|
(if (== dirty? clean)
|
||||||
state
|
state
|
||||||
(binding [*ratom-context* nil]
|
(binding [*ratom-context* nil]
|
||||||
(-deref this))))
|
(-deref this))))
|
||||||
|
@ -270,7 +274,7 @@
|
||||||
(when-not active?
|
(when-not active?
|
||||||
(when debug (swap! -running inc))
|
(when debug (swap! -running inc))
|
||||||
(set! active? true))
|
(set! active? true))
|
||||||
(set! dirty? false)
|
(set! dirty? clean)
|
||||||
(set! state res)
|
(set! state res)
|
||||||
(-notify-watches this oldstate state)
|
(-notify-watches this oldstate state)
|
||||||
res))
|
res))
|
||||||
|
@ -280,11 +284,11 @@
|
||||||
(if (or auto-run (some? *ratom-context*))
|
(if (or auto-run (some? *ratom-context*))
|
||||||
(do
|
(do
|
||||||
(notify-deref-watcher! this)
|
(notify-deref-watcher! this)
|
||||||
(if dirty?
|
(if-not (== dirty? clean)
|
||||||
(run this)
|
(run this)
|
||||||
state))
|
state))
|
||||||
(do
|
(do
|
||||||
(when dirty?
|
(when-not (== dirty? clean)
|
||||||
(let [oldstate state]
|
(let [oldstate state]
|
||||||
(set! state (f))
|
(set! state (f))
|
||||||
(when-not (identical? oldstate state)
|
(when-not (identical? oldstate state)
|
||||||
|
@ -297,7 +301,7 @@
|
||||||
(remove-watch w this))
|
(remove-watch w this))
|
||||||
(set! watching nil)
|
(set! watching nil)
|
||||||
(set! state nil)
|
(set! state nil)
|
||||||
(set! dirty? true)
|
(set! dirty? is-dirty)
|
||||||
(when active?
|
(when active?
|
||||||
(when debug (swap! -running dec))
|
(when debug (swap! -running dec))
|
||||||
(set! active? false))
|
(set! active? false))
|
||||||
|
@ -319,7 +323,7 @@
|
||||||
(defn make-reaction [f & {:keys [auto-run on-set on-dispose derefed]}]
|
(defn make-reaction [f & {:keys [auto-run on-set on-dispose derefed]}]
|
||||||
(let [runner (if (= auto-run true) run auto-run)
|
(let [runner (if (= auto-run true) run auto-run)
|
||||||
active (not (nil? derefed))
|
active (not (nil? derefed))
|
||||||
dirty (not active)
|
dirty (if (not active) is-dirty clean)
|
||||||
reaction (Reaction. f nil dirty active
|
reaction (Reaction. f nil dirty active
|
||||||
nil nil
|
nil nil
|
||||||
runner on-set on-dispose)]
|
runner on-set on-dispose)]
|
||||||
|
|
Loading…
Reference in New Issue