mirror of
https://github.com/penpot/penpot.git
synced 2025-05-13 22:16:37 +02:00
🔥 Remove duplicated change apply operation.
This commit is contained in:
parent
a03882de76
commit
e7b3f12b71
5 changed files with 20 additions and 26 deletions
|
@ -159,10 +159,8 @@
|
||||||
([changes undo-changes]
|
([changes undo-changes]
|
||||||
(commit-changes changes undo-changes {}))
|
(commit-changes changes undo-changes {}))
|
||||||
([changes undo-changes {:keys [save-undo?
|
([changes undo-changes {:keys [save-undo?
|
||||||
commit-local?
|
|
||||||
file-id]
|
file-id]
|
||||||
:or {save-undo? true
|
:or {save-undo? true}
|
||||||
commit-local? false}
|
|
||||||
:as opts}]
|
:as opts}]
|
||||||
(us/assert ::cp/changes changes)
|
(us/assert ::cp/changes changes)
|
||||||
(us/assert ::cp/changes undo-changes)
|
(us/assert ::cp/changes undo-changes)
|
||||||
|
@ -173,23 +171,20 @@
|
||||||
(let [error (volatile! nil)]
|
(let [error (volatile! nil)]
|
||||||
(ptk/reify ::commit-changes
|
(ptk/reify ::commit-changes
|
||||||
cljs.core/IDeref
|
cljs.core/IDeref
|
||||||
(-deref [_] {:file-id file-id :changes changes})
|
(-deref [_]
|
||||||
|
{:file-id file-id
|
||||||
|
:changes changes})
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [current-file-id (get state :current-file-id)
|
(let [current-file-id (get state :current-file-id)
|
||||||
file-id (or file-id current-file-id)
|
file-id (or file-id current-file-id)
|
||||||
path1 (if (= file-id current-file-id)
|
path (if (= file-id current-file-id)
|
||||||
[:workspace-file :data]
|
|
||||||
[:workspace-libraries file-id :data])
|
|
||||||
path2 (if (= file-id current-file-id)
|
|
||||||
[:workspace-data]
|
[:workspace-data]
|
||||||
[:workspace-libraries file-id :data])]
|
[:workspace-libraries file-id :data])]
|
||||||
(try
|
(try
|
||||||
(us/assert ::spec/changes changes)
|
(us/assert ::spec/changes changes)
|
||||||
(let [state (update-in state path1 cp/process-changes changes false)]
|
(update-in state path cp/process-changes changes false)
|
||||||
(cond-> state
|
|
||||||
commit-local? (update-in path2 cp/process-changes changes false)))
|
|
||||||
(catch :default e
|
(catch :default e
|
||||||
(vreset! error e)
|
(vreset! error e)
|
||||||
state))))
|
state))))
|
||||||
|
|
|
@ -211,8 +211,7 @@
|
||||||
(if (= file-id (:current-file-id state))
|
(if (= file-id (:current-file-id state))
|
||||||
(-> state
|
(-> state
|
||||||
(update-in [:workspace-file :revn] max revn)
|
(update-in [:workspace-file :revn] max revn)
|
||||||
(update :workspace-data cp/process-changes changes)
|
(update :workspace-data cp/process-changes changes))
|
||||||
(update-in [:workspace-file :data] cp/process-changes changes))
|
|
||||||
(-> state
|
(-> state
|
||||||
(update-in [:workspace-libraries file-id :revn] max revn)
|
(update-in [:workspace-libraries file-id :revn] max revn)
|
||||||
(update-in [:workspace-libraries file-id :data]
|
(update-in [:workspace-libraries file-id :data]
|
||||||
|
|
|
@ -138,8 +138,8 @@
|
||||||
|
|
||||||
(def workspace-file-colors
|
(def workspace-file-colors
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(when-let [file (:workspace-file state)]
|
(when-let [file (:workspace-data state)]
|
||||||
(->> (get-in file [:data :colors])
|
(->> (:colors file)
|
||||||
(d/mapm #(assoc %2 :file-id (:id file))))))
|
(d/mapm #(assoc %2 :file-id (:id file))))))
|
||||||
st/state))
|
st/state))
|
||||||
|
|
||||||
|
@ -150,8 +150,8 @@
|
||||||
|
|
||||||
(def workspace-file-typography
|
(def workspace-file-typography
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(when-let [file (:workspace-file state)]
|
(when-let [file (:workspace-data state)]
|
||||||
(get-in file [:data :typographies])))
|
(:typographies file)))
|
||||||
st/state))
|
st/state))
|
||||||
|
|
||||||
(def workspace-project
|
(def workspace-project
|
||||||
|
|
|
@ -811,9 +811,9 @@
|
||||||
(defn file-colors-ref
|
(defn file-colors-ref
|
||||||
[id]
|
[id]
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(let [wfile (:workspace-file state)]
|
(let [wfile (:workspace-data state)]
|
||||||
(if (= (:id wfile) id)
|
(if (= (:id wfile) id)
|
||||||
(vals (get-in wfile [:data :colors]))
|
(vals (get-in wfile [:colors]))
|
||||||
(vals (get-in state [:workspace-libraries id :data :colors])))))
|
(vals (get-in state [:workspace-libraries id :data :colors])))))
|
||||||
st/state =))
|
st/state =))
|
||||||
|
|
||||||
|
@ -821,27 +821,27 @@
|
||||||
(defn file-media-ref
|
(defn file-media-ref
|
||||||
[id]
|
[id]
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(let [wfile (:workspace-file state)]
|
(let [wfile (:workspace-data state)]
|
||||||
(if (= (:id wfile) id)
|
(if (= (:id wfile) id)
|
||||||
(vals (get-in wfile [:data :media]))
|
(vals (get-in wfile [:media]))
|
||||||
(vals (get-in state [:workspace-libraries id :data :media])))))
|
(vals (get-in state [:workspace-libraries id :data :media])))))
|
||||||
st/state =))
|
st/state =))
|
||||||
|
|
||||||
(defn file-components-ref
|
(defn file-components-ref
|
||||||
[id]
|
[id]
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(let [wfile (:workspace-file state)]
|
(let [wfile (:workspace-data state)]
|
||||||
(if (= (:id wfile) id)
|
(if (= (:id wfile) id)
|
||||||
(vals (get-in wfile [:data :components]))
|
(vals (get-in wfile [:components]))
|
||||||
(vals (get-in state [:workspace-libraries id :data :components])))))
|
(vals (get-in state [:workspace-libraries id :data :components])))))
|
||||||
st/state =))
|
st/state =))
|
||||||
|
|
||||||
(defn file-typography-ref
|
(defn file-typography-ref
|
||||||
[id]
|
[id]
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(let [wfile (:workspace-file state)]
|
(let [wfile (:workspace-data state)]
|
||||||
(if (= (:id wfile) id)
|
(if (= (:id wfile) id)
|
||||||
(vals (get-in wfile [:data :typographies]))
|
(vals (get-in wfile [:typographies]))
|
||||||
(vals (get-in state [:workspace-libraries id :data :typographies])))))
|
(vals (get-in state [:workspace-libraries id :data :typographies])))))
|
||||||
st/state =))
|
st/state =))
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@
|
||||||
(defn- make-page-ref
|
(defn- make-page-ref
|
||||||
[page-id]
|
[page-id]
|
||||||
(l/derived (fn [state]
|
(l/derived (fn [state]
|
||||||
(let [page (get-in state [:workspace-file :data :pages-index page-id])]
|
(let [page (get-in state [:workspace-data :pages-index page-id])]
|
||||||
(select-keys page [:id :name])))
|
(select-keys page [:id :name])))
|
||||||
st/state =))
|
st/state =))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue