0

I can't seem to find any information about this, and I'm not sure if this is possible.

In a standard react app, you can do something like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS Client</title>
</head>
<body>
<div id="root"></div>
<script src="external_app_sdk.js"></script>
</body>
</html>

And then in the actual react app made in javascript, you can reference anything from link-to-external-javascript.js by importing it.

I'm working on a proof-of-concept project with Kotlin/JS, trying to build a react app which needs to reference javascript which is included in the index.html file. So my file looks like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS Client</title>
</head>
<body>
<script src="Proof-of-Concept-React-App.js"></script>
<script src="external_app_sdk.js"></script>
</body>
</html>

I'm definitely not understanding how scope works here. My react components need to use javascript functions from external_app_sdk.js and I'm not sure how to get them to be usable.

FWIW: I'm working on an iframe app which sits inside a website. This imported javascript exposes an API for that website which allows data to be retrieved from "above" the iframe.

Option B: Apparently, there is also an npm package which I could potentially add to my dependencies to expose these functions in kotlin like this:

implementation(npm("external_app_sdk", "1.2.3"))

But since it's pure JS, I know that I'll need to provide wrappers. That's not an issue, but the npm module doesn't have any module exports defined, so I don't think I can actually create wrappers for it. If anyone has any info about this, that would be much appreciated.

aSemy
  • 5,485
  • 2
  • 25
  • 51
Josh
  • 69
  • 11
  • To summarise, to make sure I've understood: You're asking if Kotlin/JS bindings for `external_app_sdk.js` will work even when you don't directly define `external_app_sdk` in your Gradle dependencies? Instead `external_app_sdk` will be available by a ` – aSemy Sep 16 '22 at 21:26
  • @aSemy Basically, I'd just like to know if including external_app_sdk.js in the index.html can expose this API to kotlin at all. – Josh Sep 16 '22 at 21:28
  • Optionally, if I include the npm package INSTEAD of using the reference in the HTML file, is there an easy way to see the available exports that need kotlin wrapper functions? – Josh Sep 16 '22 at 21:30
  • The only Kotlin bindings you need to create are the ones you use in your Kotlin/JS code. So if you only use one function from `external_app_sdk`, then that's enough. The bindings don't need to be comprehensive. – aSemy Sep 16 '22 at 21:36

0 Answers0