-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #771 from IlyaGulya/feature/add-wasmJs-target-support
Support wasmJs target
- Loading branch information
Showing
54 changed files
with
419 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...uild/gradleConfiguration/src/main/kotlin/com/badoo/reaktive/configuration/WasmJsPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.badoo.reaktive.configuration | ||
|
||
import com.badoo.reaktive.getLibrary | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
class WasmJsPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
configureWasmJsCompilation(target) | ||
} | ||
|
||
private fun configureWasmJsCompilation(target: Project) { | ||
target.extensions.configure(KotlinMultiplatformExtension::class.java) { | ||
wasmJs { | ||
browser() | ||
disableIfUndefined(Target.WASM_JS) | ||
} | ||
sourceSets.getByName("wasmJsMain") { | ||
dependencies { | ||
implementation(project.getLibrary("kotlin-stdlib")) | ||
} | ||
} | ||
sourceSets.getByName("wasmJsTest") { | ||
dependencies { | ||
implementation(project.getLibrary("kotlin-test")) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
reaktive-testing/src/commonMain/kotlin/com/badoo/reaktive/test/single/AsyncTestResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.badoo.reaktive.test.single | ||
|
||
expect class AsyncTestResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
reaktive-testing/src/jsMain/kotlin/com/badoo/reaktive/test/single/AsyncTestResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.badoo.reaktive.test.single | ||
|
||
@Suppress("UnusedPrivateMember") | ||
@JsName("Promise") | ||
actual external class AsyncTestResult( | ||
executor: (resolve: (Unit) -> Unit, reject: (Throwable) -> Unit) -> Unit, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...-testing/src/jvmNativeCommonMain/kotlin/com/badoo/reaktive/test/single/AsyncTestResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.badoo.reaktive.test.single | ||
|
||
@Suppress("ACTUAL_WITHOUT_EXPECT") // We never instantiate TestResult, see https://youtrack.jetbrains.com/issue/KT-64199 | ||
actual typealias AsyncTestResult = Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
reaktive-testing/src/wasmJsMain/kotlin/com/badoo/reaktive/test/single/AsyncTestResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.badoo.reaktive.test.single | ||
|
||
@Suppress("UnusedPrivateMember") | ||
@JsName("Promise") | ||
actual external class AsyncTestResult( | ||
executor: (resolve: (JsAny) -> Unit, reject: (JsAny) -> Unit) -> Unit, | ||
) |
36 changes: 36 additions & 0 deletions
36
reaktive-testing/src/wasmJsMain/kotlin/com/badoo/reaktive/test/single/TestAwait.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.badoo.reaktive.test.single | ||
|
||
import com.badoo.reaktive.single.Single | ||
import com.badoo.reaktive.single.doOnBeforeSuccess | ||
import com.badoo.reaktive.single.map | ||
import com.badoo.reaktive.single.onErrorReturn | ||
import com.badoo.reaktive.single.subscribe | ||
|
||
actual fun <T> Single<T>.testAwait(assertError: ((Throwable) -> Unit)?, assertSuccess: (T) -> Unit): AsyncTestResult = | ||
if (assertError == null) { | ||
doOnBeforeSuccess(assertSuccess) | ||
.asTestResult() | ||
} else { | ||
map { TestAwaitResult.Success(it) } | ||
.onErrorReturn { TestAwaitResult.Error(it) } | ||
.doOnBeforeSuccess { result -> | ||
when (result) { | ||
is TestAwaitResult.Success -> assertSuccess(result.value) | ||
is TestAwaitResult.Error -> assertError(result.error) | ||
} | ||
} | ||
.asTestResult() | ||
} | ||
|
||
private fun <T> Single<T>.asTestResult(): AsyncTestResult = | ||
AsyncTestResult { resolve, reject -> | ||
subscribe( | ||
onSuccess = { resolve(Unit.toJsReference()) }, | ||
onError = { reject(it.toJsReference()) }, | ||
) | ||
} | ||
|
||
private sealed class TestAwaitResult<out T> { | ||
class Success<out T>(val value: T) : TestAwaitResult<T>() | ||
class Error(val error: Throwable) : TestAwaitResult<Nothing>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
.../com/badoo/reaktive/disposable/Various.kt → .../com/badoo/reaktive/disposable/Various.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
reaktive/src/jsCommonMain/kotlin/com/badoo/reaktive/scheduler/JsFunctions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.badoo.reaktive.scheduler | ||
|
||
internal expect fun jsSetTimeout(task: () -> Unit, delayMillis: Int): TimeoutId | ||
|
||
internal expect fun jsSetInterval(task: () -> Unit, delayMillis: Int): TimeoutId | ||
|
||
internal expect fun jsClearTimeout(id: TimeoutId) | ||
|
||
internal expect fun jsClearInterval(id: TimeoutId) |
Oops, something went wrong.