Johann Pardanaud
11/27/2022, 4:28 PMdata class SomeModel(val createdAt: Instant)
In JS and Darwin targets, do you any recommandation to provide native dates for the createdAt
property?
Details in thread ➡️ 🧵Johann Pardanaud
11/27/2022, 4:28 PM// JS
@JsExport fun SomeModel.createdAtJS() = createdAt.toJSDate()
// Darwin
val SomeModel.createdAtNS get() = createdAt.toNSDate()
However :
• The JS target doesn’t support extension properties, and the extension function is a bit deceptive being a simple function with the receiver passed as a parameter: createdAtJS(myModel)
• The model still accepts an Instant
type in its constructor, thus I can’t instantiate it from the JS/Darwin targets since I can’t provide an instance of this type. I could create functions to make the conversion tho.
• The original createdAt
property is still available and can be read from all targets.
How do you solve this in your own codebase?simon.vergauwen
11/27/2022, 4:29 PMInstant
.
https://github.com/Kotlin/kotlinx-datetimeJohann Pardanaud
11/27/2022, 4:30 PMJohann Pardanaud
11/27/2022, 4:31 PMInstant
from this lib is not JS exportableJohann Pardanaud
11/27/2022, 4:31 PMtoJSDate()
and toNSDate()
Johann Pardanaud
11/27/2022, 4:32 PMsimon.vergauwen
11/27/2022, 4:34 PMJohann Pardanaud
11/27/2022, 4:34 PMInstant
, I could use String
to accept ISO8601 strings, that way all the targets can instantiate the data classJohann Pardanaud
11/27/2022, 4:35 PM