Prevent leave stream broken on spec failed on commit-changes.

This commit is contained in:
Andrey Antukh 2020-11-30 13:50:05 +01:00 committed by Hirunatan
parent 8ae6176242
commit 3db9907c25

View file

@ -67,27 +67,34 @@
:as opts}] :as opts}]
(us/verify ::cp/changes changes) (us/verify ::cp/changes changes)
;; (us/verify ::cp/changes undo-changes) ;; (us/verify ::cp/changes undo-changes)
(ptk/reify ::commit-changes
cljs.core/IDeref
(-deref [_] changes)
ptk/UpdateEvent (let [error (volatile! nil)]
(update [_ state] (ptk/reify ::commit-changes
(let [state (update-in state [:workspace-file :data] cp/process-changes changes)] cljs.core/IDeref
(cond-> state (-deref [_] changes)
commit-local? (update :workspace-data cp/process-changes changes))))
ptk/WatchEvent ptk/UpdateEvent
(watch [_ state stream] (update [_ state]
(let [page-id (:current-page-id state)] (try
(rx/concat (let [state (update-in state [:workspace-file :data] cp/process-changes changes)]
(when (some :page-id changes) (cond-> state
(rx/of (update-indices page-id))) commit-local? (update :workspace-data cp/process-changes changes)))
(catch :default e
(vreset! error e)
state)))
(when (and save-undo? (seq undo-changes)) ptk/WatchEvent
(let [entry {:undo-changes undo-changes (watch [_ state stream]
:redo-changes changes}] (when-not @error
(rx/of (append-undo entry)))))))))) (let [page-id (:current-page-id state)]
(rx/concat
(when (some :page-id changes)
(rx/of (update-indices page-id)))
(when (and save-undo? (seq undo-changes))
(let [entry {:undo-changes undo-changes
:redo-changes changes}]
(rx/of (append-undo entry))))))))))))
(defn generate-operations (defn generate-operations
([ma mb] (generate-operations ma mb false)) ([ma mb] (generate-operations ma mb false))