mirror of
https://github.com/penpot/penpot.git
synced 2025-02-18 13:04:38 -05:00
♻️ Replace frontend transit ns usage with common transit.
This commit is contained in:
parent
2ec769981a
commit
068c94da4e
18 changed files with 43 additions and 179 deletions
|
@ -24,7 +24,6 @@
|
||||||
[app.main.worker :as uw]
|
[app.main.worker :as uw]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.common.transit :as t]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.main.data.messages :as dm]
|
[app.main.data.messages :as dm]
|
||||||
|
@ -39,7 +40,6 @@
|
||||||
[app.util.i18n :as i18n]
|
[app.util.i18n :as i18n]
|
||||||
[app.util.logging :as log]
|
[app.util.logging :as log]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
@ -1400,7 +1400,7 @@
|
||||||
(rx/merge-map (partial prepare-object objects selected))
|
(rx/merge-map (partial prepare-object objects selected))
|
||||||
(rx/reduce collect-data initial)
|
(rx/reduce collect-data initial)
|
||||||
(rx/mapcat (partial sort-selected state))
|
(rx/mapcat (partial sort-selected state))
|
||||||
(rx/map t/encode)
|
(rx/map t/encode-str)
|
||||||
(rx/map wapi/write-to-clipboard)
|
(rx/map wapi/write-to-clipboard)
|
||||||
(rx/catch on-copy-error)
|
(rx/catch on-copy-error)
|
||||||
(rx/ignore)))))))
|
(rx/ignore)))))))
|
||||||
|
@ -1420,7 +1420,7 @@
|
||||||
paste-transit-str
|
paste-transit-str
|
||||||
(->> clipboard-str
|
(->> clipboard-str
|
||||||
(rx/filter t/transit?)
|
(rx/filter t/transit?)
|
||||||
(rx/map t/decode)
|
(rx/map t/decode-str)
|
||||||
(rx/filter #(= :copied-shapes (:type %)))
|
(rx/filter #(= :copied-shapes (:type %)))
|
||||||
(rx/map #(select-keys % [:selected :objects]))
|
(rx/map #(select-keys % [:selected :objects]))
|
||||||
(rx/map paste-shape))
|
(rx/map paste-shape))
|
||||||
|
@ -1459,7 +1459,7 @@
|
||||||
image-data (wapi/extract-images paste-data)
|
image-data (wapi/extract-images paste-data)
|
||||||
text-data (wapi/extract-text paste-data)
|
text-data (wapi/extract-text paste-data)
|
||||||
decoded-data (and (t/transit? text-data)
|
decoded-data (and (t/transit? text-data)
|
||||||
(t/decode text-data))
|
(t/decode-str text-data))
|
||||||
|
|
||||||
edit-id (get-in state [:workspace-local :edition])
|
edit-id (get-in state [:workspace-local :edition])
|
||||||
is-editing-text? (and edit-id (= :text (get-in objects [edit-id :type])))]
|
is-editing-text? (and edit-id (= :text (get-in objects [edit-id :type])))]
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.common.transit :as t]
|
||||||
[app.common.uri :as u]
|
[app.common.uri :as u]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
@ -21,7 +22,6 @@
|
||||||
[app.util.avatars :as avatars]
|
[app.util.avatars :as avatars]
|
||||||
[app.util.i18n :as i18n :refer [tr]]
|
[app.util.i18n :as i18n :refer [tr]]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.websockets :as ws]
|
[app.util.websockets :as ws]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
;; Process all incoming messages.
|
;; Process all incoming messages.
|
||||||
(->> (ws/-stream wsession)
|
(->> (ws/-stream wsession)
|
||||||
(rx/filter ws/message?)
|
(rx/filter ws/message?)
|
||||||
(rx/map (comp t/decode :payload))
|
(rx/map (comp t/decode-str :payload))
|
||||||
(rx/filter #(s/valid? ::message %))
|
(rx/filter #(s/valid? ::message %))
|
||||||
(rx/map process-message))
|
(rx/map process-message))
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.router :as rt]
|
[app.util.router :as rt]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.uri :as uu]
|
[app.util.uri :as uu]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.util.http :as http]
|
[app.util.http :as http]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.util.transit :as t]
|
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
[app.util.logging :as log]
|
[app.util.logging :as log]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
(ns app.util.dom.dnd
|
(ns app.util.dom.dnd
|
||||||
"Drag & Drop interop helpers."
|
"Drag & Drop interop helpers."
|
||||||
(:require
|
(:require
|
||||||
[cuerdas.core :as str]
|
[app.common.transit :as t]
|
||||||
[app.util.data :refer (read-string)]
|
[app.util.data :refer (read-string)]
|
||||||
[app.util.transit :as t]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
;; This is the official documentation for the dnd API:
|
;; This is the official documentation for the dnd API:
|
||||||
;; https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
|
;; https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
(let [dt (.-dataTransfer e)]
|
(let [dt (.-dataTransfer e)]
|
||||||
(if (or (str/starts-with? data-type "application")
|
(if (or (str/starts-with? data-type "application")
|
||||||
(str/starts-with? data-type "penpot"))
|
(str/starts-with? data-type "penpot"))
|
||||||
(.setData dt data-type (t/encode data))
|
(.setData dt data-type (t/encode-str data))
|
||||||
(.setData dt data-type data))
|
(.setData dt data-type data))
|
||||||
e)))
|
e)))
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
(let [dt (.-dataTransfer e)]
|
(let [dt (.-dataTransfer e)]
|
||||||
(if (or (str/starts-with? data-type "penpot")
|
(if (or (str/starts-with? data-type "penpot")
|
||||||
(= data-type "application/json"))
|
(= data-type "application/json"))
|
||||||
(t/decode (.getData dt data-type))
|
(t/decode-str (.getData dt data-type))
|
||||||
(.getData dt data-type)))))
|
(.getData dt data-type)))))
|
||||||
|
|
||||||
(defn get-files
|
(defn get-files
|
||||||
|
|
|
@ -8,13 +8,13 @@
|
||||||
"A http client with rx streams interface."
|
"A http client with rx streams interface."
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.transit :as t]
|
||||||
[app.common.uri :as u]
|
[app.common.uri :as u]
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.util.cache :as c]
|
[app.util.cache :as c]
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :as globals]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
(defn transit-data
|
(defn transit-data
|
||||||
[data]
|
[data]
|
||||||
(reify IBodyData
|
(reify IBodyData
|
||||||
(-get-body-data [_] (t/encode data))
|
(-get-body-data [_] (t/encode-str data))
|
||||||
(-update-headers [_ headers]
|
(-update-headers [_ headers]
|
||||||
(assoc headers "content-type" "application/transit+json"))))
|
(assoc headers "content-type" "application/transit+json"))))
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
(let [contentype (get headers "content-type")]
|
(let [contentype (get headers "content-type")]
|
||||||
(if (and (str/starts-with? contentype "application/transit+json")
|
(if (and (str/starts-with? contentype "application/transit+json")
|
||||||
(pos? (count body)))
|
(pos? (count body)))
|
||||||
(assoc response :body (t/decode body))
|
(assoc response :body (t/decode-str body))
|
||||||
response)))
|
response)))
|
||||||
|
|
||||||
(defn success?
|
(defn success?
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
(:require
|
(:require
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.util.globals :as globals]
|
[app.util.globals :as globals]
|
||||||
[app.util.storage :refer [storage]]
|
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.transit :as t]
|
[app.util.storage :refer [storage]]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[goog.object :as gobj]
|
[goog.object :as gobj]
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(ns app.util.storage
|
(ns app.util.storage
|
||||||
(:require
|
(:require
|
||||||
[app.util.transit :as t]
|
[app.common.exceptions :as ex]
|
||||||
[app.util.timers :as tm]
|
[app.common.transit :as t]
|
||||||
[app.util.globals :as g]
|
[app.util.globals :as g]
|
||||||
[app.common.exceptions :as ex]))
|
[app.util.timers :as tm]))
|
||||||
|
|
||||||
(defn- ^boolean is-worker?
|
(defn- ^boolean is-worker?
|
||||||
[]
|
[]
|
||||||
|
@ -18,8 +18,7 @@
|
||||||
|
|
||||||
(defn- decode
|
(defn- decode
|
||||||
[v]
|
[v]
|
||||||
(ex/ignoring (t/decode v)))
|
(ex/ignoring (t/decode-str v)))
|
||||||
|
|
||||||
|
|
||||||
(defn- persist
|
(defn- persist
|
||||||
[storage prev curr]
|
[storage prev curr]
|
||||||
|
@ -29,8 +28,8 @@
|
||||||
(when (not= curr* prev*)
|
(when (not= curr* prev*)
|
||||||
(tm/schedule-on-idle
|
(tm/schedule-on-idle
|
||||||
#(if (some? curr*)
|
#(if (some? curr*)
|
||||||
(.setItem ^js storage (t/encode key) (t/encode curr*))
|
(.setItem ^js storage (t/encode-str key) (t/encode-str curr*))
|
||||||
(.removeItem ^js storage (t/encode key)))))))
|
(.removeItem ^js storage (t/encode-str key)))))))
|
||||||
|
|
||||||
(into #{} (concat (keys curr)
|
(into #{} (concat (keys curr)
|
||||||
(keys prev)))))
|
(keys prev)))))
|
||||||
|
@ -43,7 +42,7 @@
|
||||||
(let [key (.key ^js storage index)
|
(let [key (.key ^js storage index)
|
||||||
val (.getItem ^js storage key)]
|
val (.getItem ^js storage key)]
|
||||||
(try
|
(try
|
||||||
(assoc res (t/decode key) (t/decode val))
|
(assoc res (t/decode-str key) (t/decode-str val))
|
||||||
(catch :default e
|
(catch :default e
|
||||||
res))))
|
res))))
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.array :as arr]
|
[app.util.array :as arr]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.transit :as t]
|
|
||||||
[clojure.walk :as walk]
|
[clojure.walk :as walk]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
[goog.object :as gobj]
|
[goog.object :as gobj]
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.util.dom :as dom]
|
[app.util.dom :as dom]
|
||||||
[app.util.transit :as t]
|
|
||||||
[app.util.storage :refer [storage]]))
|
[app.util.storage :refer [storage]]))
|
||||||
|
|
||||||
(defonce theme (get @storage ::theme cfg/default-theme))
|
(defonce theme (get @storage ::theme cfg/default-theme))
|
||||||
|
|
|
@ -1,127 +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) UXBOX Labs SL
|
|
||||||
|
|
||||||
(ns app.util.transit
|
|
||||||
"A lightweight abstraction for transit serialization."
|
|
||||||
(:require
|
|
||||||
[cognitect.transit :as t]
|
|
||||||
[linked.core :as lk]
|
|
||||||
[linked.set :as lks]
|
|
||||||
[app.common.data :as d]
|
|
||||||
[app.common.geom.point :as gpt]
|
|
||||||
[app.common.geom.matrix :as gmt]
|
|
||||||
[app.util.time :as dt]))
|
|
||||||
|
|
||||||
(deftype Blob [content]
|
|
||||||
IDeref
|
|
||||||
(-deref [_] content))
|
|
||||||
|
|
||||||
(defn blob?
|
|
||||||
[v]
|
|
||||||
(instance? Blob v))
|
|
||||||
|
|
||||||
(def blob-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "jsonblob")
|
|
||||||
(fn [v] (js/JSON.stringify @v))))
|
|
||||||
|
|
||||||
(def blob-read-handler
|
|
||||||
(t/read-handler
|
|
||||||
(fn [value]
|
|
||||||
(->Blob (js/JSON.parse value)))))
|
|
||||||
|
|
||||||
;; --- Transit adapters
|
|
||||||
|
|
||||||
(def bigint-read-handler
|
|
||||||
(t/read-handler
|
|
||||||
(fn [value]
|
|
||||||
(js/parseInt value 10))))
|
|
||||||
|
|
||||||
(def point-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "point")
|
|
||||||
(fn [v] (into {} v))))
|
|
||||||
|
|
||||||
(def point-read-handler
|
|
||||||
(t/read-handler
|
|
||||||
(fn [value]
|
|
||||||
(gpt/map->Point value))))
|
|
||||||
|
|
||||||
(def matrix-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "matrix")
|
|
||||||
(fn [v] (into {} v))))
|
|
||||||
|
|
||||||
(def matrix-read-handler
|
|
||||||
(t/read-handler
|
|
||||||
(fn [value]
|
|
||||||
(gmt/map->Matrix value))))
|
|
||||||
|
|
||||||
(def ordered-set-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "ordered-set")
|
|
||||||
(fn [v] (vec v))))
|
|
||||||
|
|
||||||
(def ordered-set-read-handler
|
|
||||||
(t/read-handler #(into (lk/set) %)))
|
|
||||||
|
|
||||||
(def date-read-handler
|
|
||||||
(t/read-handler (fn [value] (-> value (js/parseInt 10) (dt/datetime)))))
|
|
||||||
|
|
||||||
(def duration-read-handler
|
|
||||||
(t/read-handler (fn [value] (dt/duration value))))
|
|
||||||
|
|
||||||
(def date-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "m")
|
|
||||||
(fn [v] (str (inst-ms v)))))
|
|
||||||
|
|
||||||
(def duration-write-handler
|
|
||||||
(t/write-handler
|
|
||||||
(constantly "duration")
|
|
||||||
(fn [v] (inst-ms v))))
|
|
||||||
|
|
||||||
;; --- Transit Handlers
|
|
||||||
|
|
||||||
(def ^:privare +read-handlers+
|
|
||||||
{"u" uuid
|
|
||||||
"n" bigint-read-handler
|
|
||||||
"ordered-set" ordered-set-read-handler
|
|
||||||
"jsonblob" blob-read-handler
|
|
||||||
"matrix" matrix-read-handler
|
|
||||||
"m" date-read-handler
|
|
||||||
"duration" duration-read-handler
|
|
||||||
"point" point-read-handler})
|
|
||||||
|
|
||||||
(def ^:privare +write-handlers+
|
|
||||||
{gmt/Matrix matrix-write-handler
|
|
||||||
Blob blob-write-handler
|
|
||||||
dt/DateTime date-write-handler
|
|
||||||
dt/Duration duration-write-handler
|
|
||||||
lks/LinkedSet ordered-set-write-handler
|
|
||||||
gpt/Point point-write-handler})
|
|
||||||
|
|
||||||
;; --- Public Api
|
|
||||||
|
|
||||||
(defn decode
|
|
||||||
[data]
|
|
||||||
(let [r (t/reader :json {:handlers +read-handlers+})]
|
|
||||||
(t/read r data)))
|
|
||||||
|
|
||||||
(defn encode
|
|
||||||
[data]
|
|
||||||
(try
|
|
||||||
(let [w (t/writer :json-verbose {:handlers +write-handlers+})]
|
|
||||||
(t/write w data))
|
|
||||||
(catch :default e
|
|
||||||
(throw e))))
|
|
||||||
|
|
||||||
(defn transit?
|
|
||||||
"Checks if a string can be decoded with transit"
|
|
||||||
[str]
|
|
||||||
(try
|
|
||||||
(-> str decode nil? not)
|
|
||||||
(catch js/SyntaxError e false)))
|
|
|
@ -10,7 +10,6 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.transit :as t]
|
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
(ns app.util.websockets
|
(ns app.util.websockets
|
||||||
"A interface to webworkers exposed functionality."
|
"A interface to webworkers exposed functionality."
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.transit :as t]
|
||||||
[app.common.uri :as u]
|
[app.common.uri :as u]
|
||||||
[app.config :as cfg]
|
[app.config :as cfg]
|
||||||
[app.util.transit :as t]
|
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[goog.events :as ev]
|
[goog.events :as ev]
|
||||||
[potok.core :as ptk])
|
[potok.core :as ptk])
|
||||||
|
@ -55,4 +55,4 @@
|
||||||
|
|
||||||
(defn send!
|
(defn send!
|
||||||
[ws msg]
|
[ws msg]
|
||||||
(-send ws (t/encode msg)))
|
(-send ws (t/encode-str msg)))
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
(ns app.util.worker
|
(ns app.util.worker
|
||||||
"A lightweight layer on top of webworkers api."
|
"A lightweight layer on top of webworkers api."
|
||||||
(:require
|
(:require
|
||||||
[beicon.core :as rx]
|
[app.common.transit :as t]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.util.transit :as t]))
|
[beicon.core :as rx]))
|
||||||
|
|
||||||
(declare handle-response)
|
(declare handle-response)
|
||||||
(defrecord Worker [instance stream])
|
(defrecord Worker [instance stream])
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
(rx/take-while #(not (:completed %)) ob)
|
(rx/take-while #(not (:completed %)) ob)
|
||||||
(rx/take 1 ob)))
|
(rx/take 1 ob)))
|
||||||
|
|
||||||
data (t/encode message)
|
data (t/encode-str message)
|
||||||
instance (:instance worker)]
|
instance (:instance worker)]
|
||||||
|
|
||||||
(.postMessage instance data)
|
(.postMessage instance data)
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
handle-message
|
handle-message
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [data (.-data event)
|
(let [data (.-data event)
|
||||||
data (t/decode data)]
|
data (t/decode-str data)]
|
||||||
(if (:error data)
|
(if (:error data)
|
||||||
(on-error (:error data))
|
(on-error (:error data))
|
||||||
(rx/push! bus data))))
|
(rx/push! bus data))))
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
|
|
||||||
(ns app.worker
|
(ns app.worker
|
||||||
(:require
|
(:require
|
||||||
[cljs.spec.alpha :as s]
|
|
||||||
[promesa.core :as p]
|
|
||||||
[beicon.core :as rx]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.common.transit :as t]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
[app.util.object :as obj]
|
||||||
|
[app.util.worker :as w]
|
||||||
[app.worker.impl :as impl]
|
[app.worker.impl :as impl]
|
||||||
[app.worker.selection]
|
[app.worker.selection]
|
||||||
[app.worker.thumbnails]
|
|
||||||
[app.worker.snaps]
|
[app.worker.snaps]
|
||||||
[app.util.object :as obj]
|
[app.worker.thumbnails]
|
||||||
[app.util.transit :as t]
|
[beicon.core :as rx]
|
||||||
[app.util.worker :as w]))
|
[cljs.spec.alpha :as s]
|
||||||
|
[cuerdas.core :as str]
|
||||||
|
[promesa.core :as p]))
|
||||||
|
|
||||||
;; --- Messages Handling
|
;; --- Messages Handling
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
[{:keys [sender-id payload] :as message}]
|
[{:keys [sender-id payload] :as message}]
|
||||||
(us/assert ::message message)
|
(us/assert ::message message)
|
||||||
(letfn [(post [msg]
|
(letfn [(post [msg]
|
||||||
(let [msg (-> msg (assoc :reply-to sender-id) (t/encode))]
|
(let [msg (-> msg (assoc :reply-to sender-id) (t/encode-str))]
|
||||||
(.postMessage js/self msg)))
|
(.postMessage js/self msg)))
|
||||||
|
|
||||||
(reply [result]
|
(reply [result]
|
||||||
|
@ -84,8 +84,8 @@
|
||||||
"Sends to the client a notifiction that its messages have been dropped"
|
"Sends to the client a notifiction that its messages have been dropped"
|
||||||
[{:keys [sender-id payload] :as message}]
|
[{:keys [sender-id payload] :as message}]
|
||||||
(us/assert ::message message)
|
(us/assert ::message message)
|
||||||
(.postMessage js/self (t/encode {:reply-to sender-id
|
(.postMessage js/self (t/encode-str {:reply-to sender-id
|
||||||
:dropped true})))
|
:dropped true})))
|
||||||
|
|
||||||
(defn subscribe-buffer-messages
|
(defn subscribe-buffer-messages
|
||||||
"Creates a subscription to process the buffer messages"
|
"Creates a subscription to process the buffer messages"
|
||||||
|
@ -143,7 +143,7 @@
|
||||||
[event]
|
[event]
|
||||||
(when (nil? (.-source event))
|
(when (nil? (.-source event))
|
||||||
(let [message (.-data event)
|
(let [message (.-data event)
|
||||||
message (t/decode message)]
|
message (t/decode-str message)]
|
||||||
(if (:buffer? message)
|
(if (:buffer? message)
|
||||||
(rx/push! buffer message)
|
(rx/push! buffer message)
|
||||||
(handle-message message)))))
|
(handle-message message)))))
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
(ns app.worker.impl
|
(ns app.worker.impl
|
||||||
(:require
|
(:require
|
||||||
[okulary.core :as l]
|
[app.common.pages.changes :as ch]
|
||||||
[app.util.transit :as t]
|
[app.common.transit :as t]
|
||||||
[app.common.pages.changes :as ch]))
|
[okulary.core :as l]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue