Hey Brian, been a while since that Post, Issue #1 has been resolved for a while (see http://dev.clojure.org/jira/browse/CLJS-466) but I actually switched to using proper EDN tags via IPrintWithWriter, clj/print-method and clojure.edn/read-string like you suggested.
#2 I solved indirectly via #1, I didnt find an acceptable BigDecimal JavaScript implementation and since all the math happens on the server anyways I just transmit them as Strings inside records. The Reader function in CLJS just keeps it as a String, the CLJ Reader function just does (BigDecimal. s) so all is good. (eg. #ns/money [:EUR "1234567.89"]) On Thu, May 9, 2013 at 9:03 PM, Brian Jenkins <bonky...@gmail.com> wrote: > Hi, Thomas. > > I also found this frustrating. Here's a work-around I came up with: > > > ;; assuming (defrecord Design [id name]) in namespace tektite.model.design > > (cljs.reader/register-tag-parser! "tektite.model.design.Design" > tektite.model.design/map->Design) > > (extend-protocol IPrintWithWriter > tektite.model.design/Design > (-pr-writer [coll writer opts] > (let [pr-pair (fn [keyval] (pr-sequential-writer writer pr-writer "" " > " "" opts keyval))] > (pr-sequential-writer writer pr-pair "#tektite.model.design.Design{" > ", " "}" opts coll)))) > > > On the server side, I read EDN out of the request body with > clojure.edn/read (because clojure.core/read is > unsafe for reading evil strings from the internet). clojure.edn/read > doesn't pick up new readers > from data_readers.clj or *data-readers* (fortunately), but can be taught > new tags like this: > > > (def model-readers {'tektite.model.design.Design > #'tektite.model.design/map->Design}) > > (defn read-edn-body [context] > (clojure.edn/read {:readers model-readers, :eof nil} > (java.io.PushbackReader. > (java.io.InputStreamReader. > (get-in context [:request :body]) > "UTF-8")))) > > > (I use liberator, so the request arrives in a context hash) > > Best, > Brian > > On Monday, January 7, 2013 1:13:30 AM UTC+1, Thomas Heller wrote: >> >> Hey, >> >> I'm writing a Clojure Webapp with a CLJS Frontend and expected to be able >> to cljs.reader/read-string everything I pr-str'd on the CLJ side. That >> however does not work for defrecords and BigDecimals (1.1M) . >> >> 1. defrecord >> >> In CLJ I can: >> >> (ns dummy) >> (defrecord Foo [bar]) >> (pr-str (Foo. 1)) ; => "#dummy.Foo{:bar 1}" >> >> in CLJS however this will print as >> >> "#Foo{:bar 1}" >> >> missing the Namespace. I found an old >> post<https://groups.google.com/d/msg/clojure/YSkPd4zQTKQ/757Wd4Ex8pAJ>about >> this but no other information. >> >> Also when I pr-str this record in CLJ and cljs.reader/read-string it in >> CLJS it fails with "Could not find tag parser for dummy.Foo in ("inst" >> "uuid" "queue") ", although the defrecord exists and is in the same ns >> (actually a cljsbuild crossover). I figured out that I can >> (cljs.reader/register-tag-**parser! 'dummy.Foo make-foo) but thats seems >> faulty. I read about EDN and understand why the reader would think its >> reading a Tag but I can do read-string in CLJ just fine. Shouldnt both >> sides be equal here? >> > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/clojure/4aeIxs_yNG4/unsubscribe?hl=en. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.