fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
stuartrexking 2021-03-22T06:42:23.104600Z

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>]

2021-03-22T13:20:56.106400Z

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/

❤️ 1
2021-03-22T13:22:01.106600Z

In your case I think you would need to choose your own tag, like "uri", rather than override an existing one.

tony.kay 2021-03-22T15:42:01.106900Z

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.

tony.kay 2021-03-22T15:44:19.107400Z

and a sample usage that sets up tempid support is just below that.

tony.kay 2021-03-22T15:51:57.107800Z

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.

stuartrexking 2021-03-22T22:40:28.108300Z

Thanks all for these suggestions. I will let you know how I go…

stuartrexking 2021-03-22T23:48:39.108500Z

If I follow the example in the docs here https://book.fulcrologic.com/#_custom_type_support, where is the best place to call install! ?

stuartrexking 2021-03-22T23:49:01.108700Z

After the app is mounted?

stuartrexking 2021-03-22T23:49:09.108900Z

Before? The lifecycle here isn’t clear to me.

stuartrexking 2021-03-22T23:49:46.109100Z

client-will-mount of the app?

stuartrexking 2021-03-23T00:04:19.109300Z

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

stuartrexking 2021-03-23T00:05:20.109700Z

Without the handler, it looks like this, but doesn’t work correctly.

stuartrexking 2021-03-22T06:42:45.105100Z

How do I read this as a string, or store it as a string before it goes into the database.