[WIP] JS Support
Work toward https://github.com/rickclephas/KMP-NativeCoroutines/issues/17
Let's get JS support working in here!
To Extract into Separate PRs
- [x] migrate to atomicfu: https://github.com/rickclephas/KMP-NativeCoroutines/pull/44
- [x] intermediate sourceset: https://github.com/rickclephas/KMP-NativeCoroutines/pull/45
- [x] make
nativeCoroutinesJS-friendly- [x] migrate tests to
kotlinx-coroutines-test: https://github.com/rickclephas/KMP-NativeCoroutines/pull/46 - [x] Move Apple-specific tests into
appleTesthttps://github.com/rickclephas/KMP-NativeCoroutines/commit/213f541f0abc18f3acdb9d1b76f21ce0da49afea - [x] Rename test functions to support all possible targets https://github.com/rickclephas/KMP-NativeCoroutines/commit/53fa62fa37c5e05d9988f5ce907c11b1c0cdb8ed)
- [x] migrate tests to
- [x] include JS target in
nativeCoroutinessourceset https://github.com/rickclephas/KMP-NativeCoroutines/pull/48 - [ ] define default
CoroutineScopefor JS target - [ ] add sample app with regular JS/TS consumer
- [ ] update compiler plugin to generate correct native functions/properties
- [ ] split config options into
appleandjsblocks - [ ] allow different suffix for Apple and JS
- [ ] split config options into
Open Questions
- [ ] do we need to add
@JsExport? or are the typealiases fine if we just@JsExportthe entire class in commonMain? Though we get warnings for this if it has a public suspend fun… - [ ] should the defaultCoroutineScope be different on JS than Native?
Done in this PR (will be separated into separate PRs)
Main Code
- [x] create
supportedTargetas a sourceset betweencommonandapple/js - [x] created a cross-platform
expect funforfreeze() - [x] created
PlatformErroras anexpect class- exposed as
NSErroron Apple andThrowableon JS - create an internal
kotlinCauseextension that we that we can use instead of digging intouserInfoso the tests work on non-Apple platforms
- exposed as
Tests
- [x] switch from Kotlin/Native
AtomicIntto atomicfuAtomicInt(extracted to this PR: ) - [x] copied tests from
appleTestintosupportedTargetTest- [x] convert from
fun `test method with spaces()`tofun test_method_with_underscores()because JS doesn't support spaces (even with backticks) - [x] removed freezing-related tests from
supportedTargetTest
- [x] convert from
Remaining
- [ ] figure out how to properly migrate from
runBlockingtorunTest(fromkotlinx-coroutines-test)- [x] Tests in
supportedTargetTestare passing in JS - [ ] Tests in
supportedTargetTestare currently gettingInvalidMutabilityExceptions on Native - [ ] delete overlapping tests from
AppleNative____tests and only leave freezing ones in there
- [x] Tests in
- [ ] update KSP to generate the additional methods on the JS platform
An InvalidMutabilityException seems to prevent the conversion to runTest.
Opened an issue: https://github.com/Kotlin/kotlinx.coroutines/issues/3195.
some sort of test case of consuming this code?
We should probably add a react client to the sample as discussed in https://github.com/rickclephas/KMP-NativeCoroutines/issues/17#issuecomment-1034879671.
do we need to add @JsExport? or are the typealiases fine if we just @JsExport the class?
Not 100% sure, but I think we won't need the @JsExport in the library itself.
We'll definitely need to add those to the generated functions though.