transit

Chris McCormick 2023-10-17T13:46:44.017519Z

Is there any way to preserve JS objects through transit serialization/deserialization? E.g. if I have {:a 12 :thing #js {:one "two"}} it comes out the other side as a cljs datastructure like {:a 12 :thing {"one" "two"}}.

souenzzo 2023-10-19T09:58:03.442519Z

at reader side, will be something like:

(t/read (t/reader rdr :json
          {:handlers {"js" (t/read-handler clj->js)}}))

🙏 1
Chris McCormick 2023-10-20T01:31:48.720619Z

I wonder how terrible it would be to do:

(t/read (t/reader rdr :json
          {:handlers {"js" (t/read-handler cljs.reader/read-string)}}))
And have the writer do pr-str to get EDN.

souenzzo 2023-10-18T10:20:28.717349Z

probably yes, via read/write handlers may be tricky to implement the implement the writer Handler protocol to "generic J object", but seems to be doable

Chris McCormick 2023-10-19T06:32:38.212399Z

Ok i will research this, thank you.

souenzzo 2023-10-21T11:32:49.948989Z

You can use clojure.edn/read-string in cljs Don't forget to require this ns before use EDN performance in cljs really bad. I don't have numbers but once I moved one endpoint from EDN to transit and went from "takes a few seconds" to "instant"

👍 1
Chris McCormick 2023-10-22T03:35:10.292209Z

Thanks for the heads up!

Chris McCormick 2023-10-17T13:48:54.377519Z

(the other side of a round trip I mean)