mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 05:06:10 +02:00
🎉 Add support for store plain js objects in transit.
This commit is contained in:
parent
aea7b9b6bf
commit
5ce741ba6d
1 changed files with 20 additions and 0 deletions
|
@ -11,15 +11,35 @@
|
||||||
[uxbox.util.geom.matrix :as gmt]
|
[uxbox.util.geom.matrix :as gmt]
|
||||||
[uxbox.util.time :as dt]))
|
[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
|
;; --- Transit Handlers
|
||||||
|
|
||||||
(def ^:privare +read-handlers+
|
(def ^:privare +read-handlers+
|
||||||
{"u" uuid
|
{"u" uuid
|
||||||
|
"jsonblob" blob-read-handler
|
||||||
"matrix" gmt/matrix-read-handler
|
"matrix" gmt/matrix-read-handler
|
||||||
"point" gpt/point-read-handler})
|
"point" gpt/point-read-handler})
|
||||||
|
|
||||||
(def ^:privare +write-handlers+
|
(def ^:privare +write-handlers+
|
||||||
{gmt/Matrix gmt/matrix-write-handler
|
{gmt/Matrix gmt/matrix-write-handler
|
||||||
|
Blob blob-write-handler
|
||||||
gpt/Point gpt/point-write-handler})
|
gpt/Point gpt/point-write-handler})
|
||||||
|
|
||||||
;; --- Public Api
|
;; --- Public Api
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue