cognitect / transit-cljs

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

write-handler inconsistent with Clojure counterpart #58

Closed jacobemcken closed 2 years ago

jacobemcken commented 2 years ago

The documentation and examples are very sparse so when I found:

(require '[cognitect.transit :as transit])
(def sorted-set-write-handler (transit/write-handler "sorted-set" (fn [o] (vec o))))

Source: https://www.cognitect.com/blog/2015/9/10/extending-transit

I assumed it would also work on the ClojureScript side, but I get:

Uncaught TypeError: self__.tag_fn.call is not a function

Apparently I'm supposed to wrap the string in a function:

(require '[cognitect.transit :as transit])
(def sorted-set-write-handler (transit/write-handler (fn [] "sorted-set") (fn [o] (vec o))))

Is this on purpose or should it be like its Clojure counterpart that wraps non functions in constantly (through fn-or-val)? https://github.com/cognitect/transit-clj/blob/master/src/cognitect/transit.clj#L74