I’m trying to adopt `effector` lib for Kotlin and ...
# javascript
u
I’m trying to adopt
effector
lib for Kotlin and stumbled upon the next problem. There are different config types in
effector
which are normalised before passing to factory. Normalisation uses
Object.assign
and leads to erasure of property getters, so the result object has generated property names, but no getters with initial names:
Copy code
nameOrConfig: createEffectConfig$ObjectLiteral
handler_80ch0g$_0: ƒ fetchUser$lambda(payload)
name_7uss69$_0: "Get user"
handler: (...)
name: (...)
after normalisation becomes
Copy code
config:
handler_80ch0g$_0: ƒ fetchUser$lambda(payload)
name_7uss69$_0: "Get user"
and
handler
and
name
properties are now unreachable for the library. The only way I found is using
js { ... }
wrapper and return dynamic object instead. Is there more Kotlin way to approach this problem?
r
Am I correct that the problem property has custom accessors and uses
field
? Is it possible to change kotlin code without usage of
field
?
u
So,
config
has
name
property which actually is
name_7uss69$_0
with getter, and library does (simply speaking) something like that:
Copy code
const newConfig = Object.assign({}, opts, preprocess(config))
return newConfig.name
So
newConfig
has
name_7uss69$_0
, but no getter. And initial
config
is passed as a parameter to the external function:
Copy code
external fun <Payload, Done> createEffect(config: dynamic): EffectorEffect<Payload, Done, Any>
For now I’ve solved it like that:
Copy code
fun <Payload, Done> createEffect(
        name: String,
        handler: (payload: Payload) -> Promise<Done>): EffectorEffect<Payload, Done, Any> =
        createEffect(config = js {
            this.name = name
            this.handler = handler
        })
I guess it relates to this issue: https://youtrack.jetbrains.com/issue/KT-17683