-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
transit.cljs
32 lines (25 loc) · 844 Bytes
/
transit.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns com.fulcrologic.fulcro.inspect.transit
(:require [cognitect.transit :as t]
[com.cognitect.transit.types :as ty]
[com.fulcrologic.fulcro.algorithms.transit :as ft]))
(deftype ErrorHandler []
Object
(tag [this v] "js-error")
(rep [this v] [(ex-message v) (ex-data v)])
(stringRep [this v] (ex-message v)))
(deftype DefaultHandler []
Object
(tag [this v] "unknown")
(rep [this v] (pr-str v)))
(def write-handlers
{cljs.core/ExceptionInfo (ErrorHandler.)
"default" (DefaultHandler.)})
(def read-handlers
{"js-error" (fn [[msg data]] (ex-info msg data))})
(defn read [str]
(let [reader (ft/reader {:handlers read-handlers})]
(t/read reader str)))
(defn write [x]
(let [writer (ft/writer {:handlers write-handlers})]
(t/write writer x)))
(extend-type ty/UUID IUUID)