0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🔥 Completly remove the IBatchedChange persistence method.

This commit is contained in:
Andrey Antukh 2020-07-22 12:15:43 +02:00 committed by Hirunatan
parent 4375c3eeff
commit 3040bcd6d4
3 changed files with 9 additions and 43 deletions

View file

@ -24,8 +24,6 @@
;; --- Protocols
(defprotocol IBatchedChange)
(declare setup-selection-index)
(declare update-page-indices)
(declare reset-undo)
@ -95,46 +93,19 @@
result)))))
(defn generate-changes
[prev curr]
[objects1 objects2]
(letfn [(impl-diff [res id]
(let [prev-obj (get-in prev [:objects id])
curr-obj (get-in curr [:objects id])
ops (generate-operations (dissoc prev-obj :shapes :frame-id)
(dissoc curr-obj :shapes :frame-id))]
(let [obj1 (get objects1 id)
obj2 (get objects2 id)
ops (generate-operations (dissoc obj1 :shapes :frame-id)
(dissoc obj2 :shapes :frame-id))]
(if (empty? ops)
res
(conj res {:type :mod-obj
:operations ops
:id id}))))]
(reduce impl-diff [] (set/union (set (keys (:objects prev)))
(set (keys (:objects curr)))))))
(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))))))))))
(reduce impl-diff [] (set/union (set (keys objects1))
(set (keys objects2))))))
;; --- Selection Index Handling

View file

@ -65,11 +65,6 @@
(rx/filter (ptk/type? ::changes-persisted))
(rx/tap disable-reload-stoper)
(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))))))))
(defn persist-changes

View file

@ -421,8 +421,8 @@
;; state (without temporal values in it, for this reason
;; we have 3 different objects references).
rchanges (conj (dwc/generate-changes {:objects objects1} {:objects objects2}) regchg)
uchanges (conj (dwc/generate-changes {:objects objects2} {:objects objects0}) regchg)
rchanges (conj (dwc/generate-changes objects1 objects2) regchg)
uchanges (conj (dwc/generate-changes objects2 objects0) regchg)
]
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})