This is the compiled javascript from my "SharedCod...
# javascript
t
This is the compiled javascript from my "SharedCode" Kotlin module
Copy code
...
function createApplicationScreenMessage() {
  return 'Kotlin Rocks on ' + platformName();
}
var package$kotlinnativetest = package$org.kotlinnativetest || (package$org.kotlinnativetest = {});
package$kotlinnativetest.main = main;
package$kotlinnativetest.createApplicationScreenMessageJs = createApplicationScreenMessage;
...
This is maybe a dumb question but I'm new to js. How could I call the "createApplicationScreenMessageJs" function in js?
i
Hi! It saves package, you can call something like
org.kotlinnativetest.createApplicationScreenMessage
t
got it. Thank you!
e
Is there a way remove the package from the compiled Javascript if the Kotlin application only has a single package? Ie. so one could call just
createApplicationScreenMessage()
in the above example?
t
component
plugin can do that simply for Kotlin/JS
1.3.70
https://github.com/turansky/kfc-plugins#component
i
You can write your declarations in root package (without package), so it means, that when it will be exported, it will be in top level Can you do it, or no for some reasons? What is your case?
e
@turansky Thanks. 🙂
Disable DCE
might be a problem for me though, if that's accurate. @Ilya Goncharov [JB] The use-case is a multiplatform project where I want to produce a Java package and an npm module. I know this isn't really supported (yet), but I want to preserve the package for Java consumers, so I'm reluctant to place the code in root package.
Ref. https://kotlinlang.slack.com/archives/C0B8L3U69/p1582038458410800 It kind of works right now (with a bunch of hacks), but if this could be configured either via the multiplatform plugin on with annotations, that would require fewer workarounds. I'm hoping this use-case is better supported in 1.4, as it's one I've come across a lot in enterprise, and it's mostly my motivation for looking into Kotlin multiplatform.
t
@Eivind Nilsbakken DCE disabled by
library
plugin.
component
plugin only configure DCE & Webpack
e
Will it work with a multiplatform project, or is is specifically for kotlin-js? I'll admit, I'm not terribly familiar with the Gradle ecosystem.
t
Currently it enabled for Kotlin/JS plugin only, because I had no use case.
@Eivind Nilsbakken Do you have example project on GitHub?
e
@turansky I understand. This is my example project: https://gitlab.com/fleskesvor/tabletop-enums You can see my current workaround in
src/jsMain/resources/index.js
, which is an idea I picked up from an article on this subject. I'd still need the
package.json
for my use-case (publishing to an npm registry for use by non-kotlin Javascript apps), but if the plugin can fix this specific issue, I'd no longer need
index.js
, and then most of my hacks would be limited to
build.gradle.kts
.
t
In your example you need more than "crop" package? Right?
e
I'm not sure what you mean by "crop" package. Ideally, I'd want a named export, which may be different from the root of my Kotlin files. If having it be the same is easier though, I'm fine with that.
t
Before "crop":
Copy code
const type = com.fleskesvor.tabletop.Type.BOARDGAME
After "crop":
Copy code
const type = Type.BOARDGAME
e
I see. That would be fine for my simple use-case with a single "root" enum, but it might get messy if there are many? Or maybe not, if I can access them as
Copy code
import * as TE from 'tabletop-enums';

console.log(TE.Type.BOARDGAME.description);
🤔
t
Untitled
It's after crop 🙂
e
Yes, that's perfect for the single import. 🙂 I'm wondering what the import syntax would be with multiple enums in the
com.fleskesvor.tabletop
package though. Plus, I'd need a root element to access anything in the sub packages. What would the syntax for that be like with crop?
t
"crop" - first step to ES6 imports. Now you can crop specific package (via plugin). Safe package removing for all types - compiler responsibility (via
@JsExport
).
@Eivind Nilsbakken If you mean
card
package in your example - it will be available too.
Untitled.js
e
That sounds great. 🙂 I meant if I have more enums than it would be practical to list in a single import, which is often the case in real use cases, eg. 50 files in
com.fleskesvor.tabletop
, 20 files in
com.fleskesvor.tabletop.card
, 15 in
com.fleskesvor.tabletop.dice
, and so on. EDIT: The second line would be eq.
const { Bridge, Poker, Suite } = card;
if that package also had
Bridge
and
Poker
enums, right?
t
@Eivind Nilsbakken You can use version
0.1.1
for multiplatform.
e
@turansky Awesome, thanks! 🙂 I'll check it out tonight.