https://kotlinlang.org logo
#compose
Title
# compose
j

Jamie

12/31/2021, 3:30 AM
relatively new to Kotlin, so apologies in advance if there's something dumb i'm missing 🙂 I'm currently experimenting with (Jetbrains) Compose and Decompose, and while I have a working implementation based on the Decompose samples, I'm wondering whether it's possible to use sealed classes as the exposed component value type as opposed to just a single data class as per the samples? I've tried to update as expected but this falls apart when updating the component value as there's no
copy()
method or equivalent to replicate the samples when invoking value.reduce {}, and the widget doesn't recompose when the observed
state
value changes. What am I missing? EDIT: creating a wrapper
data class
to hold my
sealed class
did the trick to make it play nice, though very much open to suggestions if there's a better way to handle this!
a

Arkadii Ivanov

12/31/2021, 12:13 PM
Perhaps you need to write an exhaustive
when
first, check for all possible subtypes, and either create initial
Loaded
, or
copy
it.
z

Zoltan Demant

12/31/2021, 2:33 PM
Isnt the problem that youre using
.apply
in your reduce function? That way youre basically updating the value, to the same value. If you use something like
.run
I believe the value will update to reflect the State.Loaded that youre specifying?
👍 1
a

Arkadii Ivanov

12/31/2021, 2:44 PM
That's definitely an issue too. From my point of none of them are actually needed here.
j

Jamie

12/31/2021, 3:50 PM
yeah the
Loaded
,
Loading
and
Error
classes in the above example definitely aren't needed for the Counter example itself, but I figured the counter would serve as a simple reference to convey what I was trying to achieve.
2 Views