silx-kit / h5web

React components for data visualization and exploration
https://h5web.panosc.eu/
MIT License
195 stars 19 forks source link

Expose utility function to enable bigint serialization in consumer apps #1706

Closed axelboc closed 2 months ago

axelboc commented 2 months ago

In preparation to adding support for bigints (cf. #1679), I add a few mock datasets with bigint literals and I implement an opt-in way to enable big int serialization for the Raw visualization and metadata viewer in consumer apps.

For JSON.stringify() to support bigint, one has to implement BigInt.prototype.toJSON. I really don't want to do this in @h5web/app or @h5web/lib because extending built-in objects is dangerous. If H5Web is integrated into an app that already implements its own JSON serialization, H5Web could unknowingly break this parent app. That's why I think it's safer to give this responsibility to the consumer app.

Since the goal is for providers to return bigint values/typed arrays if possible, and since there will always be cases where bigints need to be serialized for display (attributes, nested compounds, etc.), this should at least provide a much more robust and future-proof solution for #1536.

image

image

image

axelboc commented 2 months ago

/approve