Hello! I'm trying to make pluggable modules such t...
# javascript
p
Hello! I'm trying to make pluggable modules such that if included as dependency will execute some initialization code specified in init section of companion objects. For JVM target i'm using class scanning approach to make such logic. How to implement it for JS target?
r
From my experience you can't. Objects are lazily initialized and no code will be automatically executed just by adding a dependency. Long time ago, with the legacy compiler, I've implemented this in KVision by calling some predefined dynamic functions. But this approach doesn't work with IR. Currently I'm using "module initializers" (objects defined by modules and passed to a function which starts the application - it looks like this:https://kvision.gitbook.io/kvision-guide/1.-getting-started-1/modules).
🙏 1
t
IR compiler can check dependencies and collect initializers
p
As i know ir compiler can't scan, only get by fqName.
e
There is an issue in YouTrack for such thing, I'll dig it out tomorrow
But to answer @Robert Jaros, you can do it with
EagerInitialization
IIRC, although it's marked as deprecated. @Ilya Goncharov [JB] might know more about the deprecation status and if we can save the behavior from getting removed.
i
This deprecation status is because
EagerInitialization
is not final decision. So in fact it is way to do some initialization step, but we believe there is other way to do it beside making eager initialization of properties. So deprecation is more warning to use it carefully. Of course we will not remove it while we don’t have other ways to support initialization actions of module.
gratitude thank you 2