Merge branch 'master' of github.com:nicholaskariniemi/grub
This commit is contained in:
commit
96dd93309d
1 changed files with 16 additions and 23 deletions
|
@ -13,11 +13,10 @@
|
||||||
(defmulti handle-event (fn [event]
|
(defmulti handle-event (fn [event]
|
||||||
(:type 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)]
|
(let [history-shadow (sync/get-history-state states hash)]
|
||||||
(if history-shadow
|
(if history-shadow
|
||||||
(let [state (sync/get-current-state states)
|
(let [new-state (swap! diff/patch-state state diff)
|
||||||
new-state (diff/patch-state state diff)
|
|
||||||
new-states (sync/add-history-state states new-state)
|
new-states (sync/add-history-state states new-state)
|
||||||
new-shadow (diff/patch-state history-shadow diff)
|
new-shadow (diff/patch-state history-shadow diff)
|
||||||
new-diff (diff/diff-states new-shadow new-state)
|
new-diff (diff/diff-states new-shadow new-state)
|
||||||
|
@ -59,27 +58,21 @@
|
||||||
(go (loop [shadow initial-shadow
|
(go (loop [shadow initial-shadow
|
||||||
states (sync/new-state @state)]
|
states (sync/new-state @state)]
|
||||||
(let [[v c] (a/alts! [new-states events] :priority true)]
|
(let [[v c] (a/alts! [new-states events] :priority true)]
|
||||||
(when v
|
(cond (nil? v) nil ;; drop out of loop
|
||||||
(cond (= c new-states)
|
(= c new-states)
|
||||||
(let [current (sync/get-current-state states)]
|
(do (when-not (= shadow v)
|
||||||
(when-not (= shadow v)
|
|
||||||
(>! >remote (diff-msg shadow v)))
|
(>! >remote (diff-msg shadow v)))
|
||||||
(recur shadow
|
(recur shadow (sync/add-history-state states v)))
|
||||||
(if (= v current)
|
(= c events)
|
||||||
states
|
(let [event (assoc v
|
||||||
(sync/add-history-state states v))))
|
:states states
|
||||||
(= c events)
|
:client? client?
|
||||||
(let [event (assoc v
|
:shadow shadow
|
||||||
:states states
|
:state state)
|
||||||
:client? client?
|
{:keys [new-states new-shadow out-event]} (handle-event event)]
|
||||||
:shadow shadow)
|
(when out-event (a/put! >remote out-event))
|
||||||
{:keys [new-states new-shadow out-event]} (handle-event event)]
|
(recur (if new-shadow new-shadow shadow)
|
||||||
(when (and new-states (not= states new-states))
|
(if new-states new-states 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))))))))))
|
|
||||||
|
|
||||||
(def make-server-agent (partial make-agent false))
|
(def make-server-agent (partial make-agent false))
|
||||||
(def make-client-agent (partial make-agent true))
|
(def make-client-agent (partial make-agent true))
|
||||||
|
|
Loading…
Add table
Reference in a new issue