-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Wasm Support for kotlin-document-store #47
base: master
Are you sure you want to change the base?
Conversation
…ce set code and adapting it to WasmJs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work 🚀 Thank you for the PR!
It might be worth to commonize idb-keyval
symbols only in webMain
and use those symbols to implement the common APIs. This would drastically reduce the duplicated code. wdyt?
Also, do not forget to run on your machine before pushing changes ./gradlew ktlintFormat
to format Kotlin files automatically so that the PR can pass the Linting check
jsMain { | ||
|
||
val webMain by creating { | ||
dependsOn(commonMain.get()) | ||
dependencies { | ||
api(npm("idb-keyval", "6.2.1")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! You can use NPM libraries in wasmJs as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! it can be used but they need to be compatible with browser (which keyval is)
Thats the problem, ive tried commonizing all Edit: see https://youtrack.jetbrains.com/issue/KT-74780/KJS.-Common-definedExternally-for-KJS-and-KWasmJS |
I mean, just a top level functions such as You can express the expect fun aFunction(aParameter: String? = null)
// ...
actual fun aFunction(aParameter: String?) {
if (aParameter != null) externalJsFunction(aParameter)
else externalJsFunction()
} wdyt? |
Basically copying js source set code and adapting it to WasmJs. Since dynamic is not available in WasmJs and Promise requires a type that extends JsAny, ive had to replace all Any's and Array's and String's in Promise scope to Wasm Js versions of them (JsArray, JsString,JsAny) while allowing nullability. Since Unit is not a valid JsAny, ive had to replace it with JsAny? since i think there is no other way.
![image](https://private-user-images.githubusercontent.com/170473372/402766578-b10d1fab-75bd-4df6-8908-03af3e543419.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MzAwNzMsIm5iZiI6MTczODkyOTc3MywicGF0aCI6Ii8xNzA0NzMzNzIvNDAyNzY2NTc4LWIxMGQxZmFiLTc1YmQtNGRmNi04OTA4LTAzYWYzZTU0MzQxOS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QxMjAyNTNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yODU3NzExOWJiYzg0MjE0MjcwYzk5ZTRjZmMzM2IyMmM3ZWFhYzc3MWRlYjA2ZmUxYTUxZDg0NDZlMjNhZWZjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.CrdfkDk9rZ1BaoQuLgkB5WZaISturwixk2OTr8vC04o)
Tested in my browser and it worked. Let me know if you want any changes! (ive tried putting all in a webmain source set but definedExternally, dynamic and needing the Js variants in Wasm, ive given up and let every source set have their own impls)
(i think tests hang with promise, so idk if remove them or not)