From 163e102bcf39b919adacb8081a48d6c897cd68a6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 21 Sep 2019 20:13:14 +0200 Subject: [PATCH] :fire: Remove unused code. --- frontend/src/uxbox/main/data/shapes.cljs | 180 +----------------- frontend/src/uxbox/main/data/workspace.cljs | 27 +-- frontend/src/uxbox/main/refs.cljs | 30 --- frontend/src/uxbox/main/ui/shapes.cljs | 1 + .../uxbox/main/ui/workspace/selection.cljs | 6 +- .../src/uxbox/main/ui/workspace/viewport.cljs | 5 +- 6 files changed, 10 insertions(+), 239 deletions(-) diff --git a/frontend/src/uxbox/main/data/shapes.cljs b/frontend/src/uxbox/main/data/shapes.cljs index b7ae780ad..65b1a806c 100644 --- a/frontend/src/uxbox/main/data/shapes.cljs +++ b/frontend/src/uxbox/main/data/shapes.cljs @@ -201,21 +201,6 @@ (declare dissoc-shape) -(defn clear-empty-groups - "Given the shape, try to clean all empty groups - that this shape belongs to. - - The main purpose of this function is remove the - all empty parent groups of recently removed - shape." - [state {:keys [group] :as shape}] - (if-let [group' (get-in state [:shapes group])] - (if (empty? (:items group')) - (-> (dissoc-shape state group') - (update-in [:workspace :selected] disj (:id group'))) - state) - state)) - (defn dissoc-shape "Given a shape, removes it from the state." [state shape] @@ -259,12 +244,10 @@ (if group (as-> state $ (assoc-in $ [:shapes group :items] shapes) - (update-in $ [:shapes sid] assoc :group group) - (clear-empty-groups $ shape)) + (update-in $ [:shapes sid] assoc :group group)) (as-> state $ (assoc-in $ [:pages page :shapes] shapes) - (update-in $ [:shapes sid] dissoc :group) - (clear-empty-groups $ shape))))) + (update-in $ [:shapes sid] dissoc :group))))) (defn drop-aside [state loc tid sid] @@ -289,12 +272,10 @@ (if group (as-> state $ (assoc-in $ [:shapes group :items] shapes) - (update-in $ [:shapes sid] assoc :group group) - (clear-empty-groups $ source)) + (update-in $ [:shapes sid] assoc :group group)) (as-> state $ (assoc-in $ [:pages page :shapes] shapes) - (update-in $ [:shapes sid] dissoc :group) - (clear-empty-groups $ source))))) + (update-in $ [:shapes sid] dissoc :group))))) (def drop-after #(drop-aside %1 :after %2 %3)) (def drop-before #(drop-aside %1 :before %2 %3)) @@ -363,159 +344,6 @@ shapes (get-in state [:pages page-id :shapes])] (reduce match #{} (sequence xf shapes)))) -(defn group-shapes - [state shapes page] - (letfn [(replace-first-item [pred coll replacement] - (into [] - (concat - (take-while #(not (pred %)) coll) - [replacement] - (drop 1 (drop-while #(not (pred %)) coll))))) - - (move-shapes-to-new-group [state page shapes new-group] - (reduce (fn [state {:keys [id group] :as shape}] - (-> state - (update-in [:shapes group :items] #(remove (set [id]) %)) - (update-in [:pages page :shapes] #(remove (set [id]) %)) - (clear-empty-groups shape) - (assoc-in [:shapes id :group] new-group) - )) - state - shapes)) - - (update-shapes-on-page [state page shapes group] - (as-> (get-in state [:pages page :shapes]) $ - (replace-first-item (set shapes) $ group) - (remove (set shapes) $) - (into [] $) - (assoc-in state [:pages page :shapes] $))) - - (update-shapes-on-group [state parent-group shapes group] - (as-> (get-in state [:shapes parent-group :items]) $ - (replace-first-item (set shapes) $ group) - (remove (set shapes) $) - (into [] $) - (assoc-in state [:shapes parent-group :items] $))) - - (update-shapes-on-index [state shapes group] - (reduce (fn [state {:keys [id] :as shape}] - (as-> shape $ - (assoc $ :group group) - (assoc-in state [:shapes id] $))) - state - shapes))] - (let [sid (uuid/random) - shapes' (map #(get-in state [:shapes %]) shapes) - distinct-groups (distinct (map :group shapes')) - parent-group (cond - (not= 1 (count distinct-groups)) :multi - (nil? (first distinct-groups)) :page - :else (first distinct-groups)) - name (generate-unique-name state "Group") - group {:type :group - :name name - :items (into [] shapes) - :id sid - :page page}] - (as-> state $ - (update-shapes-on-index $ shapes' sid) - (cond - (= :multi parent-group) - (-> $ - (move-shapes-to-new-group page shapes' sid) - (update-in [:pages page :shapes] #(into [] (cons sid %)))) - (= :page parent-group) - (update-shapes-on-page $ page shapes sid) - :else - (update-shapes-on-group $ parent-group shapes sid)) - (update $ :shapes assoc sid group) - (cond - (= :multi parent-group) $ - (= :page parent-group) $ - :else (assoc-in $ [:shapes sid :group] parent-group)) - (update $ :workspace assoc :selected #{sid}))))) - -(defn degroup-shapes - [state shapes page-id] - (letfn [(get-relocation-position [state {id :id parent-id :group}] - (if (nil? parent-id) - (index-of (get-in state [:pages page-id :shapes]) id) - (index-of (get-in state [:shapes parent-id :items]) id))) - - (relocate-shape [state shape-id parent-id position] - (if (nil? parent-id) - (-> state - (update-in [:pages page-id :shapes] #(drop-at-index position % shape-id)) - (update-in [:shapes shape-id] dissoc :group)) - (-> state - (update-in [:shapes parent-id :items] #(drop-at-index position % shape-id)) - (assoc-in [:shapes shape-id :group] parent-id)))) - - (remove-group [state {id :id parent-id :group}] - (let [xform (remove #{id})] - (as-> state $ - (update $ :shapes dissoc id) - (if (nil? parent-id) - (update-in $ [:pages page-id :shapes] #(into [] xform %)) - (update-in $ [:shapes parent-id :items] #(into [] xform %)))))) - - (relocate-group-items [state {id :id parent-id :group items :items :as group}] - (let [position (get-relocation-position state group)] - (as-> state $ - (reduce #(relocate-shape %1 %2 parent-id position) $ (reverse items)) - (remove-group $ group)))) - - (select-degrouped [state groups] - (let [items (into #{} (mapcat :items groups))] - (assoc-in state [:workspace :selected] items))) - - (remove-from-parent [state id parent-id] - (assert (not (nil? parent-id)) "parent-id should never be nil here") - (update-in state [:shapes parent-id :items] #(into [] (remove #{id}) %))) - - (strip-empty-groups [state parent-id] - (if (nil? parent-id) - state - (let [group (get-in state [:shapes parent-id])] - (if (empty? (:items group)) - (-> state - (remove-group group) - (strip-empty-groups (:group group))) - state)))) - - (selective-degroup [state [shape & rest :as shapes]] - (let [group (get-in state [:shapes (:group shape)]) - position (get-relocation-position state group) - parent-id (:group group)] - (as-> state $ - (assoc-in $ [:workspace :selected] (into #{} (map :id shapes))) - (reduce (fn [state {shape-id :id}] - (-> state - (relocate-shape shape-id parent-id position) - (remove-from-parent shape-id (:id group)))) - $ (reverse shapes)) - (strip-empty-groups $ (:id group)))))] - - (let [shapes (into #{} (map #(get-in state [:shapes %])) shapes) - groups (into #{} (filter #(= (:type %) :group)) shapes) - parents (into #{} (map :group) shapes)] - (cond - (and (= (count shapes) (count groups)) - (= 1 (count parents)) - (not (empty? groups))) - (as-> state $ - (reduce relocate-group-items $ groups) - (reduce remove-group $ groups) - (select-degrouped $ groups)) - - (and (empty? groups) - (= 1 (count parents)) - (not (nil? (first parents)))) - (selective-degroup state shapes) - - :else - (throw (ex-info "invalid condition for degrouping" {})))))) - (defn materialize-xfmt [state id xfmt] (let [{:keys [type items] :as shape} (get-in state [:shapes id])] diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 463a3a9ec..f353c0dcf 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -623,8 +623,7 @@ (ptk/reify ::apply-temporal-displacement-in-bulk ptk/UpdateEvent (update [_ state] - (perf/with-measure ::apply-temporal-displacement-in-bulk - (reduce process-shape state ids)))))) + (reduce process-shape state ids))))) ;; --- Modifiers @@ -651,8 +650,7 @@ udp/IPageUpdate ptk/UpdateEvent (update [_ state] - (perf/with-measure ::materialize-current-modifier-in-bulk - (reduce process-shape state ids)))))) + (reduce process-shape state ids))))) (defn rehash-shape-relationship "Checks shape overlaping with existing canvas, if one or more @@ -970,27 +968,6 @@ (let [pid (get-in state [:workspace :current])] (update-in state [:workspace pid] assoc :selected-canvas id))))) -;; (defn watch-page-changes -;; [id] -;; (s/assert ::us/uuid id) -;; (ptk/reify ::watch-page-changes -;; ptk/WatchEvent -;; (watch [_ state stream] -;; (let [stopper (rx/filter #(= % ::stop-page-watcher) stream)] -;; (->> (rx/merge -;; (->> stream -;; (rx/filter #(or (satisfies? IPageUpdate %) -;; (= ::page-update %))) -;; (rx/map #(rehash-shape-relationship -;; (->> stream -;; (rx/filter #(satisfies? IMetadataUpdate %)) -;; (rx/debounce 1000) -;; (rx/mapcat #(rx/merge (rx/of (persist-metadata id)) -;; (->> (rx/filter metadata-persisted? stream) -;; (rx/take 1) -;; (rx/ignore)))))) -;; (rx/take-until stopper)))))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Server Interactions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/frontend/src/uxbox/main/refs.cljs b/frontend/src/uxbox/main/refs.cljs index eaa147ad2..02205392b 100644 --- a/frontend/src/uxbox/main/refs.cljs +++ b/frontend/src/uxbox/main/refs.cljs @@ -11,36 +11,6 @@ [uxbox.main.constants :as c] [uxbox.main.store :as st])) -;; TODO: move inside workspaces because this is workspace only refs - -;; --- Helpers - -(defn resolve-project - "Retrieve the current project." - [state] - (let [project-id (get-in state [:workspace :project])] - (get-in state [:projects project-id]))) - -(defn resolve-page - [state] - (let [page-id (get-in state [:workspace :page])] - (get-in state [:pages page-id]))) - -(defn- resolve-project-pages - [state] - (let [project (get-in state [:workspace :project]) - get-order #(get-in % [:metadata :order])] - (->> (vals (:pages state)) - (filter #(= project (:project %))) - (sort-by get-order)))) - -(def ^:deprecated selected-page - "Ref to the current selected page." - (-> (l/lens resolve-page) - (l/derive st/state))) - -;; --- NOT DEPRECATED - (def workspace (letfn [(selector [state] (let [id (get-in state [:workspace :current])] diff --git a/frontend/src/uxbox/main/ui/shapes.cljs b/frontend/src/uxbox/main/ui/shapes.cljs index e0da96739..e7ab7e87a 100644 --- a/frontend/src/uxbox/main/ui/shapes.cljs +++ b/frontend/src/uxbox/main/ui/shapes.cljs @@ -8,6 +8,7 @@ (:require [lentes.core :as l] [rumext.alpha :as mf] + [uxbox.main.refs :as refs] [uxbox.main.store :as st] [uxbox.main.ui.shapes.circle :as circle] [uxbox.main.ui.shapes.icon :as icon] diff --git a/frontend/src/uxbox/main/ui/workspace/selection.cljs b/frontend/src/uxbox/main/ui/workspace/selection.cljs index 97bcac7ea..85806b2c2 100644 --- a/frontend/src/uxbox/main/ui/workspace/selection.cljs +++ b/frontend/src/uxbox/main/ui/workspace/selection.cljs @@ -220,13 +220,9 @@ shape (geom/selection-rect shape)] [:& controls {:shape shape :zoom zoom :on-click on-click}])) -(def ^:private shapes-map-iref - (-> (l/key :shapes) - (l/derive st/state))) - (mf/defc selection-handlers [{:keys [wst] :as props}] - (let [shapes-map (mf/deref shapes-map-iref) + (let [shapes-map (mf/deref refs/shapes-by-id) shapes (map #(get shapes-map %) (:selected wst)) edition (:edition wst) zoom (:zoom wst 1) diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 6954bd78d..fd58f6c2d 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -88,8 +88,7 @@ (ptk/reify ::handle-selrect ptk/WatchEvent (watch [_ state stream] - (let [stoper (->> (rx/filter #(or (dw/interrupt? %) (uws/mouse-up? %)) stream) - (rx/pr-log "handle-selrect|stoper:"))] + (let [stoper (rx/filter #(or (dw/interrupt? %) (uws/mouse-up? %)) stream)] (rx/concat (rx/of (dw/deselect-all)) (->> uws/mouse-position @@ -227,8 +226,8 @@ (fn [] (events/unlistenByKey key1) (events/unlistenByKey key2))))] - (mf/use-effect on-mount) + ;; (prn "viewport$render") [:* [:& coordinates {:zoom zoom}] #_[:div.tooltip-container