How do I handle a com.cognitect.transit.URI type on the client side. In my db I can see the attribute value is
[TaggedValue: r, <https://i.pravatar.cc/300>]
https://github.com/fulcrologic/fulcro/blob/0a52e40e49f40d6b2a0c6900ba2841c4709f2af0/src/main/com/fulcrologic/fulcro/networking/http_remote.cljs#L163 for where to plug in, https://github.com/cognitect/transit-cljs/wiki/Getting-Started#writing-custom-values for more about transit handlers
There's an example of wiring up a custom transit handler at the end of this blog post, too, if it helps. https://chrisodonnell.dev/posts/giftlist/backend_persistence/
In your case I think you would need to choose your own tag, like "uri", rather than override an existing one.
So, if you study what I do for BigDecimal in RAD: I use the transit type so that I can keep accuracy on numbers. I suggest you do a similar thing for URI perhaps? There is support in Fulcro for installing a custom handler easily that affects everything now, including http, websockets, and even transit-clj->str. I think you can override an existing type if you want. I did that because my suggestion is as follows: If you have a type you really store in a database on the server, then it should work isomorphically on the client. Network, forms, etc. as that type. So, there is a https://google.github.io/closure-library/api/goog.Uri.html URI data type in CLJS. Install a handler for transit that decodes it to the client that way, and then if you were to use it in forms make a custom field type that can work with that data type (pull the string out for editing, enforce format, etc.). This also let’s you use the data type on the client fully.
and a sample usage that sets up tempid support is just below that.
If you put a transit type into a data transfer back to the server, of course that will transmit correctly, so you could also simply use the .-rep
field of the transit type to work with it directly.
Thanks all for these suggestions. I will let you know how I go…
If I follow the example in the docs here https://book.fulcrologic.com/#_custom_type_support, where is the best place to call install! ?
After the app is mounted?
Before? The lifecycle here isn’t clear to me.
client-will-mount of the app?
I can install the type-handlers and everything seems to be working fine. Only slightly weird thing is how the field is displayed in Fulcro Inspect. It looks like this now
Without the handler, it looks like this, but doesn’t work correctly.
How do I read this as a string, or store it as a string before it goes into the database.