https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Rafael Lins

11/06/2023, 8:58 PM
Heya peeps! 👋 (newcomer, so please let me know anything I've done "wrong" - like "questions should go to #blabla") I'm developing a lib with KMP and I'd like to have a better UX for users using it. For now, I'm trying to get it nicer to use in JavaScript. In JS (Browser), we apparently need to do something like
window['the.complete.artifactId:project-name']
to get to the root of the actual packages, and then call methods and all that (for example
let lib = window['all that stuff']; let example = new <http://lib.my|lib.my>.package.Something()
) Is there a way to make that base name shorter? So that users can simply
let example = <http://myLib.my|myLib.my>.package.Something()
(thereof
window['myLib']
) I'm currently using Kotlin/KMP 1.9.20 but no objections on moving back to 1.8.x ^^ Sorry if my question isn't clear 😅 (also, not linking the project yet since I'm trying to promote it or anything)
c

Christian Sciberras

11/06/2023, 10:52 PM
Hey! A bit off-topic, but I'm using your qrcode library. 😉 I'll come back to you later regarding the iOS side, I have questions. 😄
🫣 1
Regarding your point above, I'm guessing the full name is to avoid conflicts (e.g. if someone else defines myLib). I don't know how that works or what you're doing, but it feels like javascript's
import
directive is supposed to solve similar situations.
r

Rafael Lins

11/06/2023, 11:30 PM
Makes sense, I'm a bit of an old timer when it comes do JS. Not sure how imports are handled browser-side nowadays ^^ I just wanted to give the devs an easier time using the library
c

Christian Sciberras

11/07/2023, 11:58 AM
Nowadays there are modules which you can use on the client side as well. Give this a look for an intro: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules In principle, if you have a module exporting a bunch of stuff, you can import it later, even with a different name (
import { symbol_exported_with_long_name as myLib } from 'path/to/module.mjs'
). I'm not sure if or how much this relates to your problem though.
👍 1
If you need more help, we can discuss this in detail later on in DM.
r

Rafael Lins

11/07/2023, 1:37 PM
It's all right! Thanks for letting me know JS
import
is available browser-side 😄 never saw it being used before to be honest, so I kinda assumed it just wasn't feasible. Also, I was really taken by surprise by kind of randomly finding an user of my library! I have no words to describe how happy and humbled I am to know you use it! I'm really hoping you like it, and if not let me know how can I make it better! Thank you, really ❤️ (I felt like the nintendo 64 kid hahaha)
👍 1
4 Views