Skip to content

Instantly share code, notes, and snippets.

View takahirom's full-sized avatar

Takahiro Menju takahirom

View GitHub Profile
@Composable
fun Main() {
MyVerticalBox(
name = "box1",
modifier = Modifier.background(Color.Yellow)
) {
MyVerticalBox(
name = ">box2",
modifier = Modifier
.size(100.dp)
@Composable
private static final void Node2(final String name, Composer $composer, final int $changed, final int var3) {
$composer = $composer.startRestartGroup(1815931962);
int $dirty = $changed;
if ((var3 & 1) != 0) {
$dirty = $changed | 6;
} else if (($changed & 14) == 0) {
// ↓ where it is compared to the contents of the SlotTable.
$dirty = $changed | ($composer.changed(name) ? 4 : 2);
}
@Composable
fun Content() {
var state by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
delay(3000)
state = false
}
if (state) {
Node1() // ← This place is about to disappear.
}
@Composable
public static final void Content(@Nullable Composer $composer, final int $changed) {
...
// ↓↓↓↓Register the function to be called again↓↓↓↓
if (var18 != null) {
var18.updateScope((Function2)(new Function2() {
public final void invoke(@Nullable Composer $composer, int $force) {
MainKt.Content($composer, $changed | 1);
}
}));
class ViewModel {
val state = mutableStateOf("init")
}
fun main() {
val viewModel = ViewModel()
lateinit var currentScope: String
val observations = mutableMapOf<Any, String>()
val snapshot = Snapshot.takeMutableSnapshot(readObserver = {
observations[it] = currentScope
val snapshot = Snapshot.takeMutableSnapshot(readObserver = { state ->
// called when the state is read
})
fun <T> mutableStateOf(
value: T,
policy: SnapshotMutationPolicy<T> = structuralEqualityPolicy()
): MutableState<T> = createSnapshotMutableState(value, policy)
class ViewModel {
val state = mutableStateOf("init", object : SnapshotMutationPolicy<String> {
override fun equivalent(a: String, b: String): Boolean {
return a == b
val snapshot = Snapshot.takeMutableSnapshot()
thread {
viewModel.state.value = "changes from other thread"
}
snapshot.enter {
Thread.sleep(100)
println("in snapshot before change:" + viewModel.state)
viewModel.state.value = "change in snapshot"
println("in snapshot after change:" + viewModel.state)
}
class ViewModel {
val state = mutableStateOf("init")
}
fun main() {
val viewModel = ViewModel()
viewModel.state.value = "before snapshot"
val snapshot = Snapshot.takeMutableSnapshot()
// Here is GlobalSnapshot
// Create Snapshot
val snapshot = Snapshot.takeMutableSnapshot()
snapshot.enter {
// Recompose here
}