mirror of
https://github.com/penpot/penpot.git
synced 2025-02-15 03:28:25 -05:00
🔥 Completly remove the IBatchedChange persistence method.
This commit is contained in:
parent
4375c3eeff
commit
3040bcd6d4
3 changed files with 9 additions and 43 deletions
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
;; --- Protocols
|
;; --- Protocols
|
||||||
|
|
||||||
(defprotocol IBatchedChange)
|
|
||||||
|
|
||||||
(declare setup-selection-index)
|
(declare setup-selection-index)
|
||||||
(declare update-page-indices)
|
(declare update-page-indices)
|
||||||
(declare reset-undo)
|
(declare reset-undo)
|
||||||
|
@ -95,46 +93,19 @@
|
||||||
result)))))
|
result)))))
|
||||||
|
|
||||||
(defn generate-changes
|
(defn generate-changes
|
||||||
[prev curr]
|
[objects1 objects2]
|
||||||
(letfn [(impl-diff [res id]
|
(letfn [(impl-diff [res id]
|
||||||
(let [prev-obj (get-in prev [:objects id])
|
(let [obj1 (get objects1 id)
|
||||||
curr-obj (get-in curr [:objects id])
|
obj2 (get objects2 id)
|
||||||
ops (generate-operations (dissoc prev-obj :shapes :frame-id)
|
ops (generate-operations (dissoc obj1 :shapes :frame-id)
|
||||||
(dissoc curr-obj :shapes :frame-id))]
|
(dissoc obj2 :shapes :frame-id))]
|
||||||
(if (empty? ops)
|
(if (empty? ops)
|
||||||
res
|
res
|
||||||
(conj res {:type :mod-obj
|
(conj res {:type :mod-obj
|
||||||
:operations ops
|
:operations ops
|
||||||
:id id}))))]
|
:id id}))))]
|
||||||
(reduce impl-diff [] (set/union (set (keys (:objects prev)))
|
(reduce impl-diff [] (set/union (set (keys objects1))
|
||||||
(set (keys (:objects curr)))))))
|
(set (keys objects2))))))
|
||||||
|
|
||||||
(defn- generate-changes-when-idle
|
|
||||||
[& args]
|
|
||||||
(rx/create
|
|
||||||
(fn [sink]
|
|
||||||
(ts/schedule-on-idle
|
|
||||||
(fn []
|
|
||||||
(->> (apply generate-changes args)
|
|
||||||
(reduced)
|
|
||||||
(sink))
|
|
||||||
(constantly nil))))))
|
|
||||||
|
|
||||||
(defn diff-and-commit-changes
|
|
||||||
[page-id]
|
|
||||||
(ptk/reify ::diff-and-commit-changes
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ state stream]
|
|
||||||
(let [page-id (get-in state [:workspace-page :id])
|
|
||||||
curr (get-in state [:workspace-data page-id])
|
|
||||||
prev (get-in state [:workspace-pages page-id :data])]
|
|
||||||
(->> (rx/zip (generate-changes-when-idle prev curr)
|
|
||||||
(generate-changes-when-idle curr prev))
|
|
||||||
(rx/observe-on :queue)
|
|
||||||
(rx/mapcat (fn [[rchanges uchanges]]
|
|
||||||
(if (empty? rchanges)
|
|
||||||
(rx/empty)
|
|
||||||
(rx/of (commit-changes rchanges uchanges))))))))))
|
|
||||||
|
|
||||||
;; --- Selection Index Handling
|
;; --- Selection Index Handling
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,6 @@
|
||||||
(rx/filter (ptk/type? ::changes-persisted))
|
(rx/filter (ptk/type? ::changes-persisted))
|
||||||
(rx/tap disable-reload-stoper)
|
(rx/tap disable-reload-stoper)
|
||||||
(rx/ignore)
|
(rx/ignore)
|
||||||
(rx/take-until stoper))
|
|
||||||
(->> stream
|
|
||||||
(rx/filter #(satisfies? dwc/IBatchedChange %))
|
|
||||||
(rx/debounce 10)
|
|
||||||
(rx/map (fn [_] (dwc/diff-and-commit-changes page-id)))
|
|
||||||
(rx/take-until stoper))))))))
|
(rx/take-until stoper))))))))
|
||||||
|
|
||||||
(defn persist-changes
|
(defn persist-changes
|
||||||
|
|
|
@ -421,8 +421,8 @@
|
||||||
;; state (without temporal values in it, for this reason
|
;; state (without temporal values in it, for this reason
|
||||||
;; we have 3 different objects references).
|
;; we have 3 different objects references).
|
||||||
|
|
||||||
rchanges (conj (dwc/generate-changes {:objects objects1} {:objects objects2}) regchg)
|
rchanges (conj (dwc/generate-changes objects1 objects2) regchg)
|
||||||
uchanges (conj (dwc/generate-changes {:objects objects2} {:objects objects0}) regchg)
|
uchanges (conj (dwc/generate-changes objects2 objects0) regchg)
|
||||||
]
|
]
|
||||||
|
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
|
|
Loading…
Add table
Reference in a new issue