mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05: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]
|
||||
(commit-changes changes undo-changes {}))
|
||||
([changes undo-changes {:keys [save-undo?
|
||||
commit-local?
|
||||
file-id]
|
||||
:or {save-undo? true
|
||||
commit-local? false}
|
||||
:or {save-undo? true}
|
||||
:as opts}]
|
||||
(us/assert ::cp/changes changes)
|
||||
(us/assert ::cp/changes undo-changes)
|
||||
|
@ -173,23 +171,20 @@
|
|||
(let [error (volatile! nil)]
|
||||
(ptk/reify ::commit-changes
|
||||
cljs.core/IDeref
|
||||
(-deref [_] {:file-id file-id :changes changes})
|
||||
(-deref [_]
|
||||
{:file-id file-id
|
||||
:changes changes})
|
||||
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [current-file-id (get state :current-file-id)
|
||||
file-id (or file-id current-file-id)
|
||||
path1 (if (= file-id current-file-id)
|
||||
[:workspace-file :data]
|
||||
[:workspace-libraries file-id :data])
|
||||
path2 (if (= file-id current-file-id)
|
||||
path (if (= file-id current-file-id)
|
||||
[:workspace-data]
|
||||
[:workspace-libraries file-id :data])]
|
||||
(try
|
||||
(us/assert ::spec/changes changes)
|
||||
(let [state (update-in state path1 cp/process-changes changes false)]
|
||||
(cond-> state
|
||||
commit-local? (update-in path2 cp/process-changes changes false)))
|
||||
(update-in state path cp/process-changes changes false)
|
||||
(catch :default e
|
||||
(vreset! error e)
|
||||
state))))
|
||||
|
|
|
@ -211,8 +211,7 @@
|
|||
(if (= file-id (:current-file-id state))
|
||||
(-> state
|
||||
(update-in [:workspace-file :revn] max revn)
|
||||
(update :workspace-data cp/process-changes changes)
|
||||
(update-in [:workspace-file :data] cp/process-changes changes))
|
||||
(update :workspace-data cp/process-changes changes))
|
||||
(-> state
|
||||
(update-in [:workspace-libraries file-id :revn] max revn)
|
||||
(update-in [:workspace-libraries file-id :data]
|
||||
|
|
|
@ -138,8 +138,8 @@
|
|||
|
||||
(def workspace-file-colors
|
||||
(l/derived (fn [state]
|
||||
(when-let [file (:workspace-file state)]
|
||||
(->> (get-in file [:data :colors])
|
||||
(when-let [file (:workspace-data state)]
|
||||
(->> (:colors file)
|
||||
(d/mapm #(assoc %2 :file-id (:id file))))))
|
||||
st/state))
|
||||
|
||||
|
@ -150,8 +150,8 @@
|
|||
|
||||
(def workspace-file-typography
|
||||
(l/derived (fn [state]
|
||||
(when-let [file (:workspace-file state)]
|
||||
(get-in file [:data :typographies])))
|
||||
(when-let [file (:workspace-data state)]
|
||||
(:typographies file)))
|
||||
st/state))
|
||||
|
||||
(def workspace-project
|
||||
|
|
|
@ -811,9 +811,9 @@
|
|||
(defn file-colors-ref
|
||||
[id]
|
||||
(l/derived (fn [state]
|
||||
(let [wfile (:workspace-file state)]
|
||||
(let [wfile (:workspace-data state)]
|
||||
(if (= (:id wfile) id)
|
||||
(vals (get-in wfile [:data :colors]))
|
||||
(vals (get-in wfile [:colors]))
|
||||
(vals (get-in state [:workspace-libraries id :data :colors])))))
|
||||
st/state =))
|
||||
|
||||
|
@ -821,27 +821,27 @@
|
|||
(defn file-media-ref
|
||||
[id]
|
||||
(l/derived (fn [state]
|
||||
(let [wfile (:workspace-file state)]
|
||||
(let [wfile (:workspace-data state)]
|
||||
(if (= (:id wfile) id)
|
||||
(vals (get-in wfile [:data :media]))
|
||||
(vals (get-in wfile [:media]))
|
||||
(vals (get-in state [:workspace-libraries id :data :media])))))
|
||||
st/state =))
|
||||
|
||||
(defn file-components-ref
|
||||
[id]
|
||||
(l/derived (fn [state]
|
||||
(let [wfile (:workspace-file state)]
|
||||
(let [wfile (:workspace-data state)]
|
||||
(if (= (:id wfile) id)
|
||||
(vals (get-in wfile [:data :components]))
|
||||
(vals (get-in wfile [:components]))
|
||||
(vals (get-in state [:workspace-libraries id :data :components])))))
|
||||
st/state =))
|
||||
|
||||
(defn file-typography-ref
|
||||
[id]
|
||||
(l/derived (fn [state]
|
||||
(let [wfile (:workspace-file state)]
|
||||
(let [wfile (:workspace-data state)]
|
||||
(if (= (:id wfile) id)
|
||||
(vals (get-in wfile [:data :typographies]))
|
||||
(vals (get-in wfile [:typographies]))
|
||||
(vals (get-in state [:workspace-libraries id :data :typographies])))))
|
||||
st/state =))
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@
|
|||
(defn- make-page-ref
|
||||
[page-id]
|
||||
(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])))
|
||||
st/state =))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue