Use swap! in diff handling to update state
- Ensures state updates always use the current state as a basis.
This commit is contained in:
parent
dd5bf7a53a
commit
fd249cefca
1 changed files with 4 additions and 7 deletions
|
@ -13,11 +13,10 @@
|
|||
(defmulti handle-event (fn [event]
|
||||
(:type event)))
|
||||
|
||||
(defmethod handle-event :diff [{:keys [hash diff states shadow client?] :as msg}]
|
||||
(defmethod handle-event :diff [{:keys [hash diff states shadow client? state] :as msg}]
|
||||
(let [history-shadow (sync/get-history-state states hash)]
|
||||
(if history-shadow
|
||||
(let [state (sync/get-current-state states)
|
||||
new-state (diff/patch-state state diff)
|
||||
(let [new-state (swap! diff/patch-state state diff)
|
||||
new-states (sync/add-history-state states new-state)
|
||||
new-shadow (diff/patch-state history-shadow diff)
|
||||
new-diff (diff/diff-states new-shadow new-state)
|
||||
|
@ -68,11 +67,9 @@
|
|||
(let [event (assoc v
|
||||
:states states
|
||||
:client? client?
|
||||
:shadow shadow)
|
||||
:shadow shadow
|
||||
:state state)
|
||||
{:keys [new-states new-shadow out-event]} (handle-event event)]
|
||||
(when (and new-states (not= states new-states))
|
||||
(let [new-state (sync/get-current-state new-states)]
|
||||
(reset! state new-state)))
|
||||
(when out-event (a/put! >remote out-event))
|
||||
(recur (if new-shadow new-shadow shadow)
|
||||
(if new-states new-states states)))))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue