mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 15:31:38 +02:00
🐛 Make the library persistence as separated operation.
This commit is contained in:
parent
b6f359bcb8
commit
2c89b611b5
1 changed files with 31 additions and 10 deletions
|
@ -38,6 +38,7 @@
|
||||||
[app.main.store :as st]))
|
[app.main.store :as st]))
|
||||||
|
|
||||||
(declare persist-changes)
|
(declare persist-changes)
|
||||||
|
(declare persist-sychronous-changes)
|
||||||
(declare shapes-changes-persisted)
|
(declare shapes-changes-persisted)
|
||||||
(declare update-persistence-status)
|
(declare update-persistence-status)
|
||||||
|
|
||||||
|
@ -95,14 +96,17 @@
|
||||||
(rx/map deref)
|
(rx/map deref)
|
||||||
(rx/filter library-file?)
|
(rx/filter library-file?)
|
||||||
(rx/filter (complement #(empty? (:changes %))))
|
(rx/filter (complement #(empty? (:changes %))))
|
||||||
(rx/map persist-changes)
|
(rx/map persist-sychronous-changes)
|
||||||
(rx/take-until (rx/delay 100 stoper)))
|
(rx/take-until (rx/delay 100 stoper)))
|
||||||
(->> stream
|
(->> stream
|
||||||
(rx/filter (ptk/type? ::changes-persisted))
|
(rx/filter (ptk/type? ::changes-persisted))
|
||||||
(rx/tap on-saved)
|
(rx/tap on-saved)
|
||||||
(rx/ignore)
|
(rx/ignore)
|
||||||
(rx/take-until stoper)))
|
(rx/take-until stoper)))
|
||||||
(rx/subs #(st/emit! %)))))))
|
(rx/subs #(st/emit! %)
|
||||||
|
(constantly nil)
|
||||||
|
(fn []
|
||||||
|
(on-saved))))))))
|
||||||
|
|
||||||
(defn persist-changes
|
(defn persist-changes
|
||||||
[{:keys [file-id changes]}]
|
[{:keys [file-id changes]}]
|
||||||
|
@ -118,16 +122,14 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [sid (:session-id state)
|
(let [sid (:session-id state)
|
||||||
file (if (= file-id (:current-file-id state))
|
file (get state :workspace-file)
|
||||||
(get state :workspace-file)
|
|
||||||
(get-in state [:workspace-libraries file-id]))
|
|
||||||
queue (get-in state [:workspace-persistence :queue] [])
|
queue (get-in state [:workspace-persistence :queue] [])
|
||||||
|
|
||||||
xf-cat (comp (mapcat :changes))
|
xf-cat (comp (mapcat :changes))
|
||||||
changes (into [] xf-cat queue)
|
|
||||||
params {:id (:id file)
|
params {:id (:id file)
|
||||||
:revn (:revn file)
|
:revn (:revn file)
|
||||||
:session-id sid
|
:session-id sid
|
||||||
:changes changes}
|
:changes (into [] xf-cat queue)}
|
||||||
|
|
||||||
ids (into #{} (map :id) queue)
|
ids (into #{} (map :id) queue)
|
||||||
|
|
||||||
|
@ -160,9 +162,28 @@
|
||||||
(rx/delay 200)
|
(rx/delay 200)
|
||||||
(rx/mapcat #(rx/throw error))))))]
|
(rx/mapcat #(rx/throw error))))))]
|
||||||
|
|
||||||
|
(when (= file-id (:id params))
|
||||||
(->> (rp/mutation :update-file params)
|
(->> (rp/mutation :update-file params)
|
||||||
(rx/mapcat handle-response)
|
(rx/mapcat handle-response)
|
||||||
(rx/catch on-error))))))
|
(rx/catch on-error)))))))
|
||||||
|
|
||||||
|
(defn persist-sychronous-changes
|
||||||
|
[{:keys [file-id changes]}]
|
||||||
|
(us/verify ::us/uuid file-id)
|
||||||
|
(ptk/reify ::persist-synchronous-changes
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(let [sid (:session-id state)
|
||||||
|
file (get-in state [:workspace-libraries file-id])
|
||||||
|
|
||||||
|
params {:id (:id file)
|
||||||
|
:revn (:revn file)
|
||||||
|
:session-id sid
|
||||||
|
:changes changes}]
|
||||||
|
|
||||||
|
(when (:id params)
|
||||||
|
(->> (rp/mutation :update-file params)
|
||||||
|
(rx/ignore)))))))
|
||||||
|
|
||||||
|
|
||||||
(defn update-persistence-status
|
(defn update-persistence-status
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue