Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns transito.core
- "
- For easier transit handling...
- Caching of keywords, no transit UUID's.
- "
- (:require
- [cognitect.transit :as transit]
- [com.cognitect.transit :as t]))
- (deftype ^:no-doc MapBuilder []
- Object
- (init [_ node] (transient {}))
- (add [_ m k v node] (assoc! m (keyword k) v))
- (finalize [_ m node] (persistent! m)))
- (deftype ^:no-doc VectorBuilder []
- Object
- (init [_ node] (transient []))
- (add [_ v x node] (conj! v x))
- (finalize [_ v node] (persistent! v))
- (fromArray [_ arr node] (cljs.core/PersistentVector.fromArray arr true)))
- (defn reader []
- (t/reader "json"
- #js{:handlers
- (clj->js
- {"$" (fn [v] (symbol v))
- ":" (fn [v] (keyword v))
- "set" (fn [v] (into #{} v))
- "list" (fn [v] (into () (.reverse v)))
- "cmap" (fn [v]
- (loop [i 0 ret (transient {})]
- (if (< i (alength v))
- (recur (+ i 2)
- (assoc! ret (aget v i) (aget v (inc i))))
- (persistent! ret))))})
- :mapBuilder (MapBuilder.)
- :arrayBuilder (VectorBuilder.)
- :prefersStrings false}))
- (transit/read
- (reader)
- (js/JSON.stringify (clj->js {:a "b" :c ["d" {:e "f"}]})))
Add Comment
Please, Sign In to add comment