From 9454302a83bf571e57bdad109bcf4ae34b1e9981 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 23 Mar 2020 15:23:43 +0100 Subject: [PATCH] :bug: Ensure data integrity on :del-obj change impl. --- common/uxbox/common/pages.cljc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/common/uxbox/common/pages.cljc b/common/uxbox/common/pages.cljc index 1105995391..d244cf2bd4 100644 --- a/common/uxbox/common/pages.cljc +++ b/common/uxbox/common/pages.cljc @@ -215,11 +215,14 @@ (defmethod process-change :del-obj [data {:keys [id] :as change}] - (when-let [{:keys [frame-id] :as obj} (get-in data [:objects id])] - (-> data - (update :objects dissoc id) - (update-in [:objects frame-id :shapes] - (fn [s] (filterv #(not= % id) s)))))) + (when-let [{:keys [frame-id shapes] :as obj} (get-in data [:objects id])] + (let [data (update data :objects dissoc id)] + (cond-> data + (contains? (:objects data) frame-id) + (update-in [:objects frame-id :shapes] (fn [s] (filterv #(not= % id) s))) + + (seq shapes) ; Recursive delete all dependend objects + (as-> $ (reduce #(process-change %1 {:type :del-obj :id %2}) $ shapes)))))) (defmethod process-operation :set [shape op]