Skip to content

Commit

Permalink
Check in `test - change lambda from non-capturing to capturing - wrap…
Browse files Browse the repository at this point in the history
…per`
  • Loading branch information
sellmair committed Dec 18, 2024
1 parent 9d91f9a commit c1079d3
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,53 @@ class ScreenshotTests {
fixture.checkScreenshot("1-afterLambdaEngaged")
}

@MinKotlinVersion("2.1.0-beta")
@HotReloadTest
@DefaultSettingsGradleKts
@DefaultBuildGradleKts
@TestOnlyLatestVersions
fun `test - change lambda from non-capturing to capturing - wrapper`(
fixture: HotReloadTestFixture
) = fixture.runTest {
fixture initialSourceCode """
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import org.jetbrains.compose.reload.underTest.*
@Composable fun Wrapper(child: @Composable () -> Unit) {
child()
}
@Composable fun Actor(
onEvent: () -> Unit,
child: @Composable () -> Unit,
) {
onTestEvent { onEvent() }
child()
}
fun main() = underTestApplication {
var state by remember { mutableStateOf(0) }
Wrapper {
Actor(onEvent = { /* lambda body */ }) {
TestText("%state")
}
}
}
""".trimIndent().replace("%", "$")

fixture.checkScreenshot("0-before-0")

fixture.sendTestEvent()
fixture.checkScreenshot("1-afterEventWithoutAction-0")

fixture.replaceSourceCodeAndReload("/* lambda body */", "state++")
fixture.checkScreenshot("2-afterLambdaEngaged-0")

fixture.sendTestEvent()
fixture.checkScreenshot("3-afterEventWithLambdaEngaged-1")
}

@HotReloadTest
@DefaultSettingsGradleKts
@DefaultBuildGradleKts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ suspend fun HotReloadTestFixture.sendTestEvent(
return sendMessage(event) {
if(await == null) awaitAck(event)
else this.await(event)
sync()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class TransactionScope(
) {
replaceSourceCode(sourceFile, oldValue, newValue)
awaitReload()

}

fun replaceSourceCode(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.jetbrains.compose.reload.agent

import org.jetbrains.compose.reload.analysis.RuntimeInfo
import org.jetbrains.compose.reload.analysis.plus
import org.jetbrains.compose.reload.analysis.resolveInvalidationKey
import org.jetbrains.compose.reload.core.createLogger
import org.jetbrains.compose.reload.core.update
import java.lang.instrument.ClassFileTransformer
import java.lang.instrument.Instrumentation
import java.security.ProtectionDomain
import java.util.concurrent.atomic.AtomicReference

private val logger = createLogger()

Expand Down
102 changes: 16 additions & 86 deletions samples/counter/app/src/jvmMain/kotlin/App.kt
Original file line number Diff line number Diff line change
@@ -1,98 +1,28 @@
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import io.sellmair.evas.compose.EvasLaunching
import io.sellmair.evas.compose.composeValue
import io.sellmair.evas.set

@Composable
fun App() {
val applicationStateCounter = CounterState.composeValue()
var uiStateCounter by remember { mutableStateOf(0) }

Column(modifier = Modifier.padding(16.dp)) {
Row {
Text("Hot Reload Example", fontSize = 48.sp, fontWeight = FontWeight.Bold)
}

Row {
Text("Press 'command + s' in IntelliJ to see changes")
}

Spacer(Modifier.height(32.dp))

Card(elevation = CardDefaults.elevatedCardElevation()) {
Column(modifier = Modifier.padding(16.dp)) {
Row {
Text(
"🔥(Hot/Application State). This state will be retained during hot-reload!",
fontSize = 12.sp
)
}

Row {
Text("🔥Hot State Counter: ${applicationStateCounter.value}", fontSize = 24.sp)
}
}
}

Spacer(Modifier.height(32.dp))


Card(elevation = CardDefaults.elevatedCardElevation()) {
Column(modifier = Modifier.padding(16.dp)) {
Row {
Text(
"❄️(Cold/UI State). UI State is rebuilt during hot reload!",
fontSize = 12.sp
)
}

Row {
Text("❄️Cold State Counter: $uiStateCounter", fontSize = 24.sp)
}
}
}

Spacer(Modifier.height(32.dp))


Card(elevation = CardDefaults.elevatedCardElevation()) {
Column(modifier = Modifier.padding(16.dp)) {
Row {
Text(
"Hot Reload also works across modules\nEdit 'widgets/src/commonUI/SomeWidget.kt",
fontSize = 12.sp
)
}

Spacer(Modifier.height(32.dp))

Row {
Card(elevation = CardDefaults.elevatedCardElevation(defaultElevation = 4.dp)) {
Box(modifier = Modifier.padding(16.dp)) {
SomeWidget()
}
}
}
}
}

Spacer(Modifier.height(32.dp))

Row(modifier = Modifier.fillMaxWidth()) {
Button(onClick = EvasLaunching {
uiStateCounter++
CounterState.set(CounterState(applicationStateCounter.value + 1))
}) {
Text("Inc! ", fontSize = 48.sp)
var count by remember { mutableStateOf(0) }
Card(modifier = Modifier.fillMaxSize().padding(32.dp)) {
Column {
Text("Counter: $count", fontSize = 48.sp)
Button(onClick = { count++ }) {
Text("JetBrains", fontSize = 48.sp)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions samples/counter/app/src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.sellmair.evas.States
import io.sellmair.evas.compose.installEvas
import org.jetbrains.compose.reload.DevelopmentEntryPoint
import org.slf4j.LoggerFactory
import java.awt.Color
import java.io.File

fun main() {
Expand All @@ -27,6 +28,7 @@ fun main() {
width = 600.dp, height = 800.dp, position = WindowPosition.Aligned(Alignment.TopEnd)
)
) {
window.background = Color.WHITE
installEvas(events, states) {
DevelopmentEntryPoint {
App()
Expand Down

0 comments on commit c1079d3

Please sign in to comment.