cognitect / transit-cljs

Transit for ClojureScript
http://transit-format.org
Apache License 2.0
324 stars 21 forks source link

back ~r Uri type with goog.Uri #16

Open sgrove opened 9 years ago

sgrove commented 9 years ago

URIs as tagged values aren't very useful generally speaking, so right now I'm doing:

(deftype URIHandler []
    Object
  (tag [this v] "r")
  (rep [this v] (.toString v))
  (stringRep [this v] nil))

(def transit-reader
  (transit/reader :json
                  {:handlers
                   {"r" (fn [uri] (Uri. uri))}}))

(def transit-writer
  (transit/writer :json
                  {:handlers
                   {goog.Uri (URIHandler.)}}))

Would be nice to actually have this built into transit-cljs, though I'm not sure what the implications for running anywhere that goog.closure has a hard time reaching (self-hosting issue?).

dustingetz commented 2 years ago

agree - cljs.core/uri? is defined and hardcoded to goog.Uri since 1.9. I understand that transit-js should neither depend on goog.Uri nor provide an explicit uri handler, but it seems like transit-cljs should align to clojurescript

dustingetz commented 2 years ago

perhaps this is why:

(= (goog.Uri. "http://localhost:8080/a?b#c")
   (goog.Uri. "http://localhost:8080/a?b#c"))
=> false

(= (java.net.URI. "http://localhost:8080/a?b#c")
   (java.net.URI. "http://localhost:8080/a?b#c"))
=> true
dustingetz commented 2 years ago

Note transit-java and transit-clj also decline to read to java.net.URI (in disalignment with the language uri? predicate), instead reading as cct.Uri

dustingetz commented 2 years ago

Related: HOWTO install #uri reader extension in Clojure/Script