<@U33H6SB2B> How to create `RequestInit` object fr...
# javascript
r
@turansky How to create
RequestInit
object from
kotlin-wrappers
in common or wasmjs code? The
invoke()
is only available (generated somehow?) in the js source set.
t
Workaround for now
r
So I need to declare my own external type with `var`s ?
I'll probably wait until it's fixed ...
I wonder why do you declare all these external types with `val`s and not with `var`s in the first place. It's an unnecessary limitation in my opinion.
In my lib I provide a function which allows user to customize the request with an optional parameter
requestFilter: (suspend RequestInit.() -> Unit)? = null
.
RequestInit
from stdlib has `var`s, so the user can modify the provided request parameters. With `val`s it can't be done so easy.
t
It doesn't work in common case, when you want more specific type for property in child interface
r
It's still a limitation. With
var
you can do the same as with
val
and more. And the JS objects are mutable anyway, so why not use mutable Kotlin values?
t
For builder, which you want, you can create mutable child. But
copy
is more kotlinish solution for this case.
In common case we want same logic as for data classes - immutable by default with
copy
method for transformation.
Single problem for now - missed
js-plain-objects
plugin support for WasmJS. cc @Artem Kobzar
And the JS objects are mutable anyway
No. It can be frozen 🧌 With Object.freeze or new JSON.parseImmutable https://github.com/tc39/proposal-json-parseimmutable
AFAIK React props are frozen inside component for example😜
r
Ok, got the point 🙂
🙂 1