KotlinJS support
See original GitHub issueIs your feature request related to a problem? Please describe. Koin can’t be used with Kotlin code targeting JavaScript.
Describe the solution you’d like I believe it would be possible to make Koin a multiplatform project. As far as I understand, this is the current structure of the various modules:
My proposal is to create a new, platform-independent koin-core-common
module, which would have no JVM dependencies. The current koin-core
module could be renamed to koin-core-jvm
, and add back in any features’ implementation that had to be removed from the new root module - for example, reading System properties. I hope this can be done without any of the other existing clients of the koin-core
module having to change at all (except for importing a module with a new name). This is what this would look like:
As for adding JVM-specific features to what the common module contains, any JVM specific methods could be expect
methods in the common modules, implemented as they currently are on the JVM, and as no-ops in other platform specific core modules.
At the same time, a new koin-core-js
module could be added, which depends on the common module. This would implement any expect
declarations of the common module (for example, the Stack
class). The artifact of this module could be published as a .jar
file to Maven repositories just like with the JVM artifacts, and then be imported to Gradle or Maven based KotlinJS projects.
To test the JS module, most JUnit tests found in koin-test
can be converted to use kotlin-test that can be run with Mocha for example - it’s mostly a matter of changing imports and renaming functions since the JS target won’t allow spaces even in identifiers escaped with backticks.
To avoid having to maintain these tests in two different modules, they could even be moved to a koin-test-common
module, which uses the appropriate common distribution of kotlin-test:
Then, the koin-test-js
module would run all common tests compiled to JavaScript as well as any JavaScript-specific tests using Mocha, and the koin-test-jvm
module would compile the common tests to bytecode, and run them as JUnit tests along with any JVM-specific tests. Again, the hope is that consumers of the current koin-test
module would not have to change their implementations at all.
Work I’ve already done on this I’m already maintaining a bit of a dirty fork of Koin targeting KotlinJS here. I’ve been using this for a while now, and it works great for me. This project shows how the framework can be published for the JS target, and it shows the test setup for kotlin-test-js as well as the converted-from-JUnit tests.
In addition to this, I’ve now created a proper fork where I did the bare minimum that’s necessary to get the core module compiled to JavaScript. This commit that I tried to annotate as best I could shows what would essentially be have to be done to the framework to make it into a common multiplatform module (except for the parts where it already substitutes JS solutions, like for the Stack
implementation, that would be an expect
declaration in the real common module of course).
I hope this all makes sense, I’m eager to hear any and all feedback on this, and I’d be happy to contribute most of the work necessary to make this happen. I just didn’t want to show up with a pull request that completely reorganizes the project without asking for input first.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:7 (7 by maintainers)
If this sounds good, I’ll try to start working on it around the end of the month, I think I can make time for it then.
Hey, if nobody else is working on this yet, I’ll get started on it this week. probably tomorrow.