relatively new to Kotlin, so apologies in advance ...
# compose
j
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
Perhaps you need to write an exhaustive
when
first, check for all possible subtypes, and either create initial
Loaded
, or
copy
it.
z
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
That's definitely an issue too. From my point of none of them are actually needed here.
j
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.