Hi, I posed this in the Feed, but maybe it is bett...
# javascript
j
Hi, I posed this in the Feed, but maybe it is better here - would anyone be able to help me build a kotlin wrapper for PouchDb? I created some code using Dukat, but it's a bit messy. Be nice if that could be formalised into a proper wrapper project. Is it correct that once I do that then I can use PouchDb in the common code of a shared Kotlin KMM project?
b
Not quite. Code built for js target will only be usable from other js targets in consumer projects. If you want a true mpp library, you need to either write all your code in commonMain sourceSet or provide expect/actual declarations between common and platform sourceSets.
On a side note, dukat is far from perfect and is best used only as a starting point when building kotlin.js wrappers. Here's some help with understanding how to write external declarations manually.
j
thank you
my idea is that we have a JS library to share with a React Native client built with Kotlin, but leverage the KMM approach to interface that JS library to an ios module for hardware access only - we can then share that JS library to a browser as well, all be it that the native layer would be inaccessible or implemented using alternative JS code
b
Ok, you're misunderstanding what kmm is. You cannot interract with react native via kmm as that is only targeting native android and ios targets. React native is just a js target from kmp perspective.
Have a thorough read here to better understand how kotlin targets work.
j
I understood usually KMM only for building a complete client app on some single target and reuse the kotlin for both. But, with JS as a KMM target, then shouldn't it be possible to have some JS layer to expose the functions for a JS client like React Native to consume? And also have a native project to access hardware also accessible from kotlin? As I understand it there is this extern capability to integrate the different modules so we have external calls potentially? I saw someone wrote an article on medium about this but the writer said it was tough.
b
Don't think it's possible. You either go with native apps and share code via KMM or React Native apps with an option to write code in kotlin.js
j
ok, thanks, maybe it's just easier to go back to TypeScript, but writing React Native as Kotlin looks interesting! What would be the benefits vs just doing React Native?
k
interface that JS library to an ios module for hardware access only
It’s hard to explain, but you can’t do this. What you’d need is some form of interop between Kotlin/JS and Kotlin/Native (or Kotlin/JVM on Android). The language they compile from is all Kotlin, but the targets are as naturally incompatible as would be Kotlin/JVM talking to Kotlin/Native compiled for Android (they can communicate, but it’s as if the Kotlin/Native is just another C library).
The closest thing I’m aware of that would do this would be https://github.com/cashapp/zipline, but that’s using a different JS runtime, so for sure wouldn’t work out of the box for RN
What would be the benefits vs just doing React Native?
Of KMM and Kotlin? That’s a long discussion, and if you’re sold on RN as the core tech, I’m not sure where to start 🙂
j
The client has a large community of React devs and React Native at least allows some of the React web code to be reused in the React Native. What I was hoping for was to gain the power and flexibility of kotlin for the business logic, and kmm for its ease of integration.
Anyway, appreciate very much your time for this discussion.