mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
🐛 Prevent out of order write on pages.
This commit is contained in:
parent
a9253f5f51
commit
527acac92e
2 changed files with 43 additions and 22 deletions
|
@ -54,14 +54,25 @@
|
|||
(t/is (= [id-b id-c id-a] (get-in res [:objects uuid/zero :shapes])))))))
|
||||
|
||||
(t/deftest process-change-mod-obj
|
||||
(let [data cp/default-page-data
|
||||
chg {:type :mod-obj
|
||||
:id uuid/zero
|
||||
:operations [{:type :set
|
||||
:attr :name
|
||||
:val "foobar"}]}
|
||||
res (cp/process-changes data [chg])]
|
||||
(t/is (= "foobar" (get-in res [:objects uuid/zero :name])))))
|
||||
(t/testing "simple mod-obj"
|
||||
(let [data cp/default-page-data
|
||||
chg {:type :mod-obj
|
||||
:id uuid/zero
|
||||
:operations [{:type :set
|
||||
:attr :name
|
||||
:val "foobar"}]}
|
||||
res (cp/process-changes data [chg])]
|
||||
(t/is (= "foobar" (get-in res [:objects uuid/zero :name])))))
|
||||
|
||||
(t/testing "mod-obj for not existing shape"
|
||||
(let [data cp/default-page-data
|
||||
chg {:type :mod-obj
|
||||
:id (uuid/next)
|
||||
:operations [{:type :set
|
||||
:attr :name
|
||||
:val "foobar"}]}
|
||||
res (cp/process-changes data [chg])]
|
||||
(t/is (= res cp/default-page-data)))))
|
||||
|
||||
|
||||
(t/deftest process-change-del-obj-1
|
||||
|
|
|
@ -194,30 +194,40 @@
|
|||
(defn process-changes
|
||||
[data items]
|
||||
(->> (us/verify ::changes items)
|
||||
(reduce #(or (process-change %1 %2) %1) data)))
|
||||
(reduce #(do
|
||||
;; (prn "process-change" (:type %2) (:id %2))
|
||||
(or (process-change %1 %2) %1))
|
||||
data)))
|
||||
|
||||
(declare insert-at-index)
|
||||
|
||||
(defmethod process-change :add-obj
|
||||
[data {:keys [id obj frame-id index] :as change}]
|
||||
(assert (contains? (:objects data) frame-id) "process-change/add-obj")
|
||||
(let [obj (assoc obj
|
||||
[data {:keys [id obj frame-id parent-id index] :as change}]
|
||||
(let [parent-id (or parent-id frame-id)
|
||||
objects (:objects data)]
|
||||
(when (and (contains? objects parent-id)
|
||||
(contains? objects frame-id))
|
||||
(let [obj (assoc obj
|
||||
:frame-id frame-id
|
||||
:parent-id parent-id
|
||||
:id id)]
|
||||
(-> data
|
||||
(update :objects assoc id obj)
|
||||
(update-in [:objects frame-id :shapes]
|
||||
(fn [shapes]
|
||||
(cond
|
||||
(some #{id} shapes) shapes
|
||||
(nil? index) (conj shapes id)
|
||||
:else (insert-at-index shapes index [id])))))))
|
||||
(-> data
|
||||
(update :objects assoc id obj)
|
||||
(update-in [:objects parent-id :shapes]
|
||||
(fn [shapes]
|
||||
(cond
|
||||
(some #{id} shapes) shapes
|
||||
(nil? index) (conj shapes id)
|
||||
:else (insert-at-index shapes index [id])))))))))
|
||||
|
||||
(defmethod process-change :mod-obj
|
||||
[data {:keys [id operations] :as change}]
|
||||
(assert (contains? (:objects data) id) "process-change/mod-obj")
|
||||
(update-in data [:objects id]
|
||||
#(reduce process-operation % operations)))
|
||||
(update data :objects
|
||||
(fn [objects]
|
||||
(if-let [obj (get objects id)]
|
||||
(assoc objects id (reduce process-operation obj operations))
|
||||
objects))))
|
||||
|
||||
(defmethod process-change :mov-obj
|
||||
[data {:keys [id frame-id] :as change}]
|
||||
|
|
Loading…
Add table
Reference in a new issue