From 60b241e86719bc1e72dba39baa5acdf025e08fa4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 10 Sep 2020 13:48:17 +0200 Subject: [PATCH] :fire: Remove unused code. --- frontend/src/app/main/data/media.cljs | 3 +- .../main/data/workspace/notifications.cljs | 64 +++++++++++-------- .../app/main/data/workspace/selection.cljs | 5 +- .../app/main/ui/workspace/shapes/path.cljs | 1 - frontend/src/app/util/blob.cljs | 31 --------- frontend/src/app/util/dom.cljs | 1 - frontend/src/app/util/files.cljs | 44 ------------- frontend/src/app/util/interop.cljs | 25 -------- frontend/src/app/util/websockets.cljs | 11 +++- 9 files changed, 49 insertions(+), 136 deletions(-) delete mode 100644 frontend/src/app/util/blob.cljs delete mode 100644 frontend/src/app/util/files.cljs delete mode 100644 frontend/src/app/util/interop.cljs diff --git a/frontend/src/app/main/data/media.cljs b/frontend/src/app/main/data/media.cljs index dd31763ec..bdab5699b 100644 --- a/frontend/src/app/main/data/media.cljs +++ b/frontend/src/app/main/data/media.cljs @@ -20,8 +20,7 @@ [app.util.router :as rt] [app.common.uuid :as uuid] [app.util.time :as ts] - [app.util.router :as r] - [app.util.files :as files])) + [app.util.router :as r])) ;; --- Specs diff --git a/frontend/src/app/main/data/workspace/notifications.cljs b/frontend/src/app/main/data/workspace/notifications.cljs index 4fc40268d..38ab4f189 100644 --- a/frontend/src/app/main/data/workspace/notifications.cljs +++ b/frontend/src/app/main/data/workspace/notifications.cljs @@ -11,6 +11,7 @@ (:require [app.common.data :as d] [app.common.geom.point :as gpt] + [app.common.pages :as cp] [app.common.spec :as us] [app.main.data.workspace.common :as dwc] [app.main.data.workspace.persistence :as dwp] @@ -26,8 +27,7 @@ [clojure.set :as set] [potok.core :as ptk])) -;; TODO: this module need to be revisited. - +(declare process-message) (declare handle-presence) (declare handle-pointer-update) (declare handle-file-change) @@ -57,30 +57,45 @@ (->> (rx/timer interval interval) (rx/map #(send-keepalive file-id))) (->> (ws/-stream wsession) - (rx/filter #(= :message (:type %))) + (rx/filter ws/message?) (rx/map (comp t/decode :payload)) (rx/filter #(s/valid? ::message %)) - (rx/map (fn [{:keys [type] :as msg}] - (case type - :presence (handle-presence msg) - :pointer-update (handle-pointer-update msg) - :file-change (handle-file-change msg) - ::unknown)))) - + (rx/map process-message)) (->> stream (rx/filter ms/pointer-event?) (rx/sample 50) (rx/map #(handle-pointer-send file-id (:pt %))))) - (rx/take-until stoper)))))) -(defn send-keepalive +(defn- process-message + [{:keys [type] :as msg}] + (case type + :presence (handle-presence msg) + :pointer-update (handle-pointer-update msg) + :file-change (handle-file-change msg) + ::unknown)) + +(defn- send-keepalive [file-id] (ptk/reify ::send-keepalive ptk/EffectEvent (effect [_ state stream] (when-let [ws (get-in state [:ws file-id])] - (ws/-send ws (t/encode {:type :keepalive})))))) + (ws/send! ws {:type :keepalive}))))) + +(defn- handle-pointer-send + [file-id point] + (ptk/reify ::handle-pointer-update + ptk/EffectEvent + (effect [_ state stream] + (let [ws (get-in state [:ws file-id]) + sid (:session-id state) + pid (:current-page-id state) + msg {:type :pointer-update + :page-id pid + :x (:x point) + :y (:y point)}] + (ws/send! ws msg))))) ;; --- Finalize Websocket @@ -159,24 +174,19 @@ :updated-at (dt/now) :page-id page-id)))))) -(defn handle-pointer-send - [file-id point] - (ptk/reify ::handle-pointer-update - ptk/EffectEvent - (effect [_ state stream] - (let [ws (get-in state [:ws file-id]) - sid (:session-id state) - pid (:current-page-id state) - msg {:type :pointer-update - :page-id pid - :x (:x point) - :y (:y point)}] - (ws/-send ws (t/encode msg)))))) +(s/def ::type keyword?) +(s/def ::profile-id uuid?) +(s/def ::file-id uuid?) +(s/def ::session-id uuid?) +(s/def ::revn integer?) +(s/def ::changes ::cp/changes) -;; TODO: add specs +(s/def ::file-change-event + (s/keys :req-un [::type ::profile-id ::file-id ::session-id ::revn ::changes])) (defn handle-file-change [{:keys [file-id changes] :as msg}] + (us/assert ::file-change-event msg) (ptk/reify ::handle-file-change ptk/WatchEvent (watch [_ state stream] diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index 6b161caa2..77e0ad2dd 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -178,15 +178,12 @@ objects (dwc/lookup-page-objects state page-id) group (get objects group-id) children (map #(get objects %) (:shapes group)) - - ;; TODO: consider using d/seek instead of filter+first - selected (->> children (filter #(geom/has-point? % position)) first)] + selected (d/seek #(geom/has-point? % position) children)] (when selected (rx/of deselect-all (select-shape (:id selected)))))))) ;; --- Duplicate Shapes -;; (declare prepare-duplicate-changes) (declare prepare-duplicate-change) (declare prepare-duplicate-frame-change) (declare prepare-duplicate-shape-change) diff --git a/frontend/src/app/main/ui/workspace/shapes/path.cljs b/frontend/src/app/main/ui/workspace/shapes/path.cljs index cb05c2a2a..91389707b 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path.cljs @@ -20,7 +20,6 @@ [app.main.ui.workspace.shapes.common :as common] [app.main.data.workspace.drawing :as dr] [app.util.dom :as dom] - [app.util.interop :as itr] [app.main.streams :as ms] [app.util.timers :as ts])) diff --git a/frontend/src/app/util/blob.cljs b/frontend/src/app/util/blob.cljs deleted file mode 100644 index dac605648..000000000 --- a/frontend/src/app/util/blob.cljs +++ /dev/null @@ -1,31 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2016 Andrey Antukh - -(ns app.util.blob - "Helpers for work with HTML5 Blob objects.") - -;; TODO: DEPRECATED - -(defn ^boolean blob? - [v] - (instance? js/Blob v)) - -(defn create - "Create a blob from content." - ([content] - (create content "application/octet-stream")) - ([content mimetype] - (js/Blob. #js [content] #js {:type mimetype}))) - -(defn revoke-uri - [url] - (js/URL.revokeObjectURL url)) - -(defn create-uri - "Create a url from blob." - [b] - {:pre [(blob? b)]} - (js/URL.createObjectURL b)) diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index b346d7567..ca4611c1f 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -14,7 +14,6 @@ [beicon.core :as rx] [cuerdas.core :as str] [app.common.geom.point :as gpt] - [app.util.blob :as blob] [app.util.transit :as ts])) ;; --- Deprecated methods diff --git a/frontend/src/app/util/files.cljs b/frontend/src/app/util/files.cljs deleted file mode 100644 index f1a00123c..000000000 --- a/frontend/src/app/util/files.cljs +++ /dev/null @@ -1,44 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2016 Andrey Antukh - -(ns app.util.files - "A interop helpers for work with files." - (:require [beicon.core :as rx] - [cuerdas.core :as str] - [app.util.blob :as blob])) - -;; TODO: DEPRECATED - -(defn read-as-text - [file] - (rx/create - (fn [sink] - (let [fr (js/FileReader.)] - (aset fr "onload" #(sink (rx/end (.-result fr)))) - (.readAsText fr file) - (constantly nil))))) - -(defn read-as-dataurl - [file] - (rx/create - (fn [sick] - (let [fr (js/FileReader.)] - (aset fr "onload" #(sick (rx/end (.-result fr)))) - (.readAsDataURL fr file)) - (constantly nil)))) - -(defn get-image-size - [file] - (letfn [(on-load [sink img] - (let [size [(.-width img) (.-height img)]] - (sink (rx/end size)))) - (on-subscribe [sink] - (let [img (js/Image.) - uri (blob/create-uri file)] - (set! (.-onload img) (partial on-load sink img)) - (set! (.-src img) uri) - #(blob/revoke-uri uri)))] - (rx/create on-subscribe))) diff --git a/frontend/src/app/util/interop.cljs b/frontend/src/app/util/interop.cljs deleted file mode 100644 index abdbca6b9..000000000 --- a/frontend/src/app/util/interop.cljs +++ /dev/null @@ -1,25 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) 2016 Andrey Antukh - -(ns app.util.interop - "Interop helpers.") - -;; TODO: this can be optimized using es6-iterator-seq -(defn iterable->seq - "Convert an es6 iterable into cljs Seq." - [v] - (seq (js/Array.from v))) - -(defn obj-assign! - ([a b] - (js/Object.assign a b)) - ([a b & more] - (reduce obj-assign! (obj-assign! a b) more))) - -(defn obj-assoc! - [obj attr value] - (unchecked-set obj attr value) - obj) diff --git a/frontend/src/app/util/websockets.cljs b/frontend/src/app/util/websockets.cljs index 5a0ba1f6f..d394354f9 100644 --- a/frontend/src/app/util/websockets.cljs +++ b/frontend/src/app/util/websockets.cljs @@ -10,9 +10,10 @@ (ns app.util.websockets "A interface to webworkers exposed functionality." (:require - [goog.events :as ev] [app.config :as cfg] + [app.util.transit :as t] [beicon.core :as rx] + [goog.events :as ev] [potok.core :as ptk]) (:import goog.Uri @@ -63,3 +64,11 @@ (ev/unlistenByKey lk1) (ev/unlistenByKey lk2) (ev/unlistenByKey lk3))))) + +(defn message? + [msg] + (= (:type msg) :message)) + +(defn send! + [ws msg] + (-send ws (t/encode msg)))