-
Notifications
You must be signed in to change notification settings - Fork 101
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 js target #887
Add js target #887
Conversation
return mapping | ||
} | ||
|
||
val identifier = "${kClass.simpleName ?: kClass.hashCode()}(${mappings.size})" |
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.
Note: This name doesn't differentiate against a genericized Workflow (although IIRC this same problem exists with kClass.qualifiedName
in the native implementations too). Should I have put a comment here to mention this limitation?
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.
Definitely put the comment about the limitations. Where were you seeing this problem for the kotlin native code? Do you have a link I can read more about this?
Was this a suggested solution for this with kotlin-js? Or something you invented?
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.
If I run the following against the JVM, it doesn't include the generic type:
data class GenericType<T>(
val t: T
)
val someType = GenericType<String>(t = "abc")
println(someType::class.qualifiedName) // prints "com.squareup.sandbox.GenericType"
As for this implementation, I invented this solution. This seems to work in practice since it appears Kotlin/JS uses a static class (probably stored on its prototype) to represent the KClass. Open to suggestions though!
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.
Ah I C what you mean now. Usuallly that is when the identifier would be overridden I believe.
@@ -0,0 +1,22 @@ | |||
package com.squareup.workflow1 | |||
|
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.
I can't see what's different here that we are requiring to expect/actual these? Is it in a later commit?
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.
it's subtle but js uses simpleName
instead of qualifiedName
in the other targets
@@ -198,7 +200,7 @@ internal class WorkflowInterceptorTest { | |||
key: String, | |||
sideEffect: suspend CoroutineScope.() -> Unit | |||
) { | |||
runBlocking { sideEffect() } | |||
launch { sideEffect() } |
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.
where do we ensure that this gets run? Here and elsewhere you could be using runTest(UnconfinedTestDispatcher()
if we want everythign to go ahead eagerly.
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.
Ah I might have missed this one, but I've added advanceUntilIdle()
where these are required, I should add this here as well to prevent confusion.
But I've confirmed this isn't required in this particular test as though this normally could be ran in parallel, the render()+assertion still always happens at the end of the test in the single thread since it's within the test-method-level runTest block.
Does that make sense? Though it's possible I might be reading this wrong https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html
return mapping | ||
} | ||
|
||
val identifier = "${kClass.simpleName ?: kClass.hashCode()}(${mappings.size})" |
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.
Definitely put the comment about the limitations. Where were you seeing this problem for the kotlin native code? Do you have a link I can read more about this?
Was this a suggested solution for this with kotlin-js? Or something you invented?
@@ -93,7 +93,7 @@ class RenderWorkflowInTest { | |||
} | |||
|
|||
@Test | |||
fun side_effects_from_initial_rendering_in_root_workflow_are_never_started_when_scope_cancelled_before_start() { | |||
fun `side_effects_from_initial_rendering_in_root_workflow_are_never_started_when_scope_cancelled_before_start`() { |
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.
So we can use backticks just not spaces? was this becasue ktlint was failing these without the backticks?
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 precisely, we can use backticks but no special characters when compiling to JS.
ktlint marks this as a MAX_LENGTH violation without the backticks
.github/workflows/kotlin.yml
Outdated
@@ -164,6 +164,34 @@ jobs : | |||
with : | |||
report_paths : '**/build/test-results/test/TEST-*.xml' | |||
|
|||
js-tests : | |||
name : JS Tests | |||
runs-on : macos-latest |
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.
I'd recommend ubuntu over macos for non-iOS things. macos minutes cost 10x more.
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.
The macOS runners are actually free now for public repos, but there's a limit of 5 concurrent jobs so it's still a good idea to use them sparingly.
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.
good to know, I've changed to ubuntu cause these don't need mac at all.
actual val EXPECTED_ERRORS = listOf( | ||
"ErrorLoggingInterceptor.logBeforeMethod threw exception:\n" + | ||
IllegalArgumentException::class.qualifiedName.toString(), | ||
"ErrorLoggingInterceptor.logAfterMethod threw exception:\n" + | ||
IllegalArgumentException::class.qualifiedName.toString() | ||
) |
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.
If the only platform-specific part of this class is this companion object constant, then you could also move the constant to top-level and put the rest of the implementation back in common.
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.
fixed!
297e8a4
to
4a84676
Compare
@steve-the-edwards ready for a final pass |
@@ -25,3 +25,5 @@ POM_DEVELOPER_ID=square | |||
POM_DEVELOPER_NAME=Square, Inc. | |||
POM_DEVELOPER_URL=https://github.com/square/ | |||
SONATYPE_STAGING_PROFILE=com.squareup | |||
|
|||
kotlin.js.compiler=ir |
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.
Do we have a link to a support article describing why this is the best?
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.
https://kotlinlang.org/docs/js-ir-compiler.html
Rather than directly generating JavaScript code from Kotlin source code, the Kotlin/JS IR compiler backend leverages a new approach. Kotlin source code is first transformed into a Kotlin intermediate representation (IR), which is subsequently compiled into JavaScript. For Kotlin/JS, this enables aggressive optimizations, and allows improvements on pain points that were present in the previous compiler, such as generated code size (through dead code elimination), and JavaScript and TypeScript ecosystem interoperability, to name some examples.
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.
Thanks! I should have been clearer though with the comment. I meant can you include that link as a comment in the .properties file so we have reference in the future
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.
would just adding the link suffice? or do we prefer also a snippet of what this is?
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.
added a bit of comment explaining the choice and the link
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.
LGTM!
* Add JS currentTimeMillis(). * Replace JS unavailable reflection usages. * Update tests.
…gInterceptor for jsTargets.
7fd8a25
to
138c87c
Compare
Rebased after the Kotlin 1.6.21 update.
Reviewing by commits should help.
Will clean up commits once reviewed.