0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 08:29:42 -05:00

🎉 Add support for store plain js objects in transit.

This commit is contained in:
Andrey Antukh 2020-04-23 14:46:43 +02:00
parent aea7b9b6bf
commit 5ce741ba6d

View file

@ -11,15 +11,35 @@
[uxbox.util.geom.matrix :as gmt]
[uxbox.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 Handlers
(def ^:privare +read-handlers+
{"u" uuid
"jsonblob" blob-read-handler
"matrix" gmt/matrix-read-handler
"point" gpt/point-read-handler})
(def ^:privare +write-handlers+
{gmt/Matrix gmt/matrix-write-handler
Blob blob-write-handler
gpt/Point gpt/point-write-handler})
;; --- Public Api