question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is 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:

koin_current

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:

koin_proposed

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:

koin_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:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
zsmb13commented, May 5, 2018

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.

2reactions
zsmb13commented, May 21, 2018

Hey, if nobody else is working on this yet, I’ll get started on it this week. probably tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin for JavaScript
Kotlin /JS provides the ability to transpile your Kotlin code, the Kotlin standard library, and any compatible dependencies to JavaScript.
Read more >
Set up a Kotlin/JS project
Like any other Gradle projects, Kotlin/JS projects support traditional Gradle dependency declarations in the dependencies section of the build ...
Read more >
Get started with Kotlin/JS for React
This tutorial demonstrates how to use IntelliJ IDEA for creating a frontend application with Kotlin/JS for React. To get started, install the ...
Read more >
Kotlin/JS IR compiler
The Kotlin/JS IR compiler is capable of generating TypeScript definitions from your Kotlin code. These definitions can be used by JavaScript ...
Read more >
kotlin.js - Kotlin Programming Language
An interface for indexing access to a collection of key-value pairs, where type of key is String and type of value is Any?....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found