I'm exporting a singleton object `Assets` that inherits from `CoroutineScope`. It has a number of su...
d
I'm exporting a singleton object
Assets
that inherits from
CoroutineScope
. It has a number of suspend functions. I
@JsExport.Ignore
them. However, they appear to still be defined in the built Javascript:
Copy code
var $de = <http://_.de|_.de> || (<http://_.de|_.de> = {});
    var $de$fabmax = $de.fabmax || ($de.fabmax = {});
    var $de$fabmax$kool = $de$fabmax.kool || ($de$fabmax.kool = {});
    defineProp($de$fabmax$kool, 'Assets', Assets_getInstance, VOID);
    $de$fabmax$kool.Assets.$loadBlobAssetCOROUTINE$1 = $loadBlobAssetCOROUTINE$1;
    $de$fabmax$kool.Assets.$loadTextureDataCOROUTINE$2 = $loadTextureDataCOROUTINE$2;
    $de$fabmax$kool.Assets.$loadTextureAtlasDataCOROUTINE$3 = $loadTextureAtlasDataCOROUTINE$3;
    $de$fabmax$kool.Assets.$loadCubeMapTextureDataCOROUTINE$4 = $loadCubeMapTextureDataCOROUTINE$4;
    $de$fabmax$kool.Assets.$loadTexture1dCOROUTINE$5 = $loadTexture1dCOROUTINE$5;
    $de$fabmax$kool.Assets.$loadTexture2dCOROUTINE$6 = $loadTexture2dCOROUTINE$6;
    $de$fabmax$kool.Assets.$loadTexture2dCOROUTINE$7 = $loadTexture2dCOROUTINE$7;
    $de$fabmax$kool.Assets.$loadTexture3dCOROUTINE$8 = $loadTexture3dCOROUTINE$8;
    $de$fabmax$kool.Assets.$loadTexture3dCOROUTINE$9 = $loadTexture3dCOROUTINE$9;
    $de$fabmax$kool.Assets.$loadCubeMapCOROUTINE$10 = $loadCubeMapCOROUTINE$10;
    $de$fabmax$kool.Assets.$loadCubeMapCOROUTINE$11 = $loadCubeMapCOROUTINE$11;
Somehow, I don't know why, the first COROUTINE assignment seems to cause the Assets object to be initialized (lazy instantiation at first reference), which leads to errors for me since it expects a number of things to be defined before that initialization. Is this the expected behavior?
t
Lazy initialization - expected behaviour
d
I know that. But I'm not the one referencing Assets. Is it the expected behavior that merely exporting a function that has a
suspend
function would cause it to automatically be initialized.
My javascript contains nothing EXCEPT the import of the ".js".
t
would cause it to automatically be initialized
Looks like expected, because you export singleton instance
d
Ok, but that's different from the behavior in Kotlin, correct? In Kotlin, merely importing the library does not instantiate it.
Whereas, merely importing the library in Javascript causes it to be initialized.
And it ONLY happens for the singleton instance that has the
suspend
function. There are others that are not initialized. That's why it doesn't seem like intended behavior.
t
Now I’m not sure which behaviour is expected too 🙂
d
I will try to create a sample project that shows the issue. The current project I'm doing it on is far too large.
I imagine it's either a) not intended behavior and avoidable or b) not ideal behavior but unavoidable.