🔥 Remove unused code.

This commit is contained in:
Andrey Antukh 2020-09-10 13:48:17 +02:00 committed by Alonso Torres
parent 0dbcfcbc0b
commit 60b241e867
9 changed files with 49 additions and 136 deletions

View file

@ -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

View file

@ -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]

View file

@ -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)

View file

@ -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]))

View file

@ -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 <niwi@niwi.nz>
(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))

View file

@ -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

View file

@ -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 <niwi@niwi.nz>
(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)))

View file

@ -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 <niwi@niwi.nz>
(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)

View file

@ -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)))