To customise printing of records, I usually add a print-method:
(defrecord Op [type value]
Object
(toString [op]
(str [type value])))
(defmethod print-method Op
[v w]
(.write w (str v)))
but when I'm in clojurescript, I'm getting an error:
Use of undeclared Var synchrony.operation/print-method at line 11
how would I do this in cljs?
I think the way to do this in ClojureScript is to extend the IPrintWithWriter
protocol to your object, e.g.
(extend-protocol IPrintWithWriter
mycool.newObj
(-pr-writer [new-obj writer _]
(write-all writer "#myObj \"" (:details new-obj) "\"")))
I can't find much official documentation on this, so there may be another/better way to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With