diff --git a/frontend/src/uxbox/main/data/workspace/common.cljs b/frontend/src/uxbox/main/data/workspace/common.cljs index e2d42ea95..d81cb608a 100644 --- a/frontend/src/uxbox/main/data/workspace/common.cljs +++ b/frontend/src/uxbox/main/data/workspace/common.cljs @@ -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 diff --git a/frontend/src/uxbox/main/data/workspace/persistence.cljs b/frontend/src/uxbox/main/data/workspace/persistence.cljs index 629f57d2e..2233e09ca 100644 --- a/frontend/src/uxbox/main/data/workspace/persistence.cljs +++ b/frontend/src/uxbox/main/data/workspace/persistence.cljs @@ -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 diff --git a/frontend/src/uxbox/main/data/workspace/transforms.cljs b/frontend/src/uxbox/main/data/workspace/transforms.cljs index ebbae44ed..57313fd38 100644 --- a/frontend/src/uxbox/main/data/workspace/transforms.cljs +++ b/frontend/src/uxbox/main/data/workspace/transforms.cljs @@ -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})