Closed reneederer closed 1 year ago
@reneederer Why do you return a boxed list from the server?
On the client, I need to display a table with different column types. One of the columns has cells that contain list of dates.
I fetch the table rows from the server as list<list<obj>>
, and in the date-column-case, obj
is list<DateTimeOffset>
Is this understandable? Can I solve it without boxing/unboxing?
@reneederer I see, working with dynamic data can be annoying. Note that on the client side, unbox
doesn't do anything at runtime! This is not a bug, that's by design. So depending on the shape of data (list<list<obj>>
in this case) the runtime representation might not be unboxable to the type you want.
I do suggest you use a proper type for sending data from server to client:
[<RequireQualififedAccess>]
type TableField =
| Text of string
| Date of DateTimeOffset
| List of TableField list
type TableRow = TableRow of Map<string, TableField>
type DatabaseApi = {
events : unit -> Async<TableRow list>
}
Then on the client, you can try to render the data in the table or I am guessing you are using a component? Then you would have to write a utility function that converts the data into array<array<obj>>
before giving that to the component
Ok, thanks for the quick answer!
Hi,
from the server, I return a boxed list
On the client, unboxing via
prints
I would have expected: datesAsList has length 2, datesAsArray throws an exception.
Furthermore, trying to access
datesAsArray.[0].DateTime
throwsI found an ugly workaround with