mirror of https://github.com/status-im/reagent.git
Make cursor used cached reactions
This commit is contained in:
parent
653e4c15f9
commit
fdef5e6c9f
|
@ -29,10 +29,23 @@
|
||||||
[:input {:value @val
|
[:input {:value @val
|
||||||
:on-change #(reset! val (.-target.value %))}]])
|
:on-change #(reset! val (.-target.value %))}]])
|
||||||
|
|
||||||
|
(defn name-part [key]
|
||||||
|
(get-in @person [:name key]))
|
||||||
|
|
||||||
|
(def monitor reagent.ratom/monitor)
|
||||||
|
|
||||||
|
(defn foo [])
|
||||||
|
|
||||||
(defn name-edit [n]
|
(defn name-edit [n]
|
||||||
(let [{:keys [first-name last-name]} @n]
|
(let [{:keys [first-name last-name]} @n]
|
||||||
[:div
|
[:div
|
||||||
[:p "I'm editing " first-name " " last-name "."]
|
[:p "I'm editing " first-name " " last-name "."]
|
||||||
|
[:p "I'm editing " @(monitor name-part :first-name) " "
|
||||||
|
@(monitor name-part :last-name) "."]
|
||||||
|
[:p "I'm editing " @(monitor name-part :first-name) " "
|
||||||
|
@(monitor name-part :last-name) "."]
|
||||||
|
[:p "I'm editing " @(monitor name-part :first-name) " "
|
||||||
|
@(monitor name-part :last-name) "."]
|
||||||
|
|
||||||
[input "First name: " (r/wrap first-name
|
[input "First name: " (r/wrap first-name
|
||||||
swap! n assoc :first-name)]
|
swap! n assoc :first-name)]
|
||||||
|
|
|
@ -166,14 +166,6 @@
|
||||||
(= ratom (.-ratom other))))
|
(= ratom (.-ratom other))))
|
||||||
|
|
||||||
Object
|
Object
|
||||||
(_reaction [this]
|
|
||||||
(if (nil? reaction)
|
|
||||||
(set! reaction
|
|
||||||
(if (satisfies? IDeref ratom)
|
|
||||||
(make-reaction #(get-in @ratom path))
|
|
||||||
(make-reaction #(ratom path))))
|
|
||||||
reaction))
|
|
||||||
|
|
||||||
(_peek [this]
|
(_peek [this]
|
||||||
(binding [*ratom-context* nil]
|
(binding [*ratom-context* nil]
|
||||||
(-deref this)))
|
(-deref this)))
|
||||||
|
@ -187,7 +179,12 @@
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [this]
|
(-deref [this]
|
||||||
(let [oldstate state
|
(let [oldstate state
|
||||||
newstate (-deref (._reaction this))]
|
newstate (if-some [r reaction]
|
||||||
|
(-deref r)
|
||||||
|
(let [f (if (satisfies? IDeref ratom)
|
||||||
|
#(get-in @ratom path)
|
||||||
|
#(ratom path))]
|
||||||
|
(cached-reaction f [ratom path ::cursor] this)))]
|
||||||
(._set-state this oldstate newstate)
|
(._set-state this oldstate newstate)
|
||||||
newstate))
|
newstate))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue