Fork me on GitHub
#fulcro
<
2021-03-22
>
stuartrexking06:03:23

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

Chris O’Donnell13:03:56

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/

❤️ 3
Chris O’Donnell13:03:01

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

tony.kay15:03:01

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.kay15:03:19

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

tony.kay15:03:57

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.

stuartrexking22:03:28

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

stuartrexking23:03:39

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

stuartrexking23:03:01

After the app is mounted?

stuartrexking23:03:09

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

stuartrexking23:03:46

client-will-mount of the app?

stuartrexking00:03:19

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

stuartrexking00:03:20

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

stuartrexking06:03:45

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