refactor: new undo/redo implementation

Previous undo/redo requires to handle every editor operation including
any new ops. The new implemenation focus on db attributes instead of
ops, it assumes that most attributes can be safely overwritten except
:block/parent, block/order and other ref-type attributes. It works likes:
1. If a block has been moved by another client (:block/parent or
:block/order has been changed), the whole tx will be skipped
2. If a refed entity has been deleted, the datom will be skipped
This commit is contained in:
Tienson Qin
2024-05-14 17:57:31 +08:00
parent 70f915839f
commit d142cf227e
6 changed files with 225 additions and 20 deletions

View File

@@ -553,13 +553,14 @@ when undo this op, this original entity-map will be transacted back into db")
(:gen-undo-boundary-op? tx-meta true)
tx-meta)))
(defn record-editor-info!
[repo page-block-uuid editor-info]
(swap! (:undo/repo->page-block-uuid->undo-ops @worker-state/*state)
update-in [repo page-block-uuid]
(fn [stack]
(when (seq stack)
(conj (vec stack) [::record-editor-info editor-info])))))
(comment
(defn record-editor-info!
[repo page-block-uuid editor-info]
(swap! (:undo/repo->page-block-uuid->undo-ops @worker-state/*state)
update-in [repo page-block-uuid]
(fn [stack]
(when (seq stack)
(conj (vec stack) [::record-editor-info editor-info]))))))
;;; listen db changes and push undo-ops (ends)