I have a data/state question. In my business layer...
# compose-desktop
h
I have a data/state question. In my business layer I fetch data-points from a webservice and synchronize a local db. I have a listener API where I can execute code every time a new datapoint is ready. All this happens in the
<http://Dispatchers.IO|Dispatchers.IO>
coroutine scope. Now, since I'm a compose noob, I have a mutable state list, where I append the datapoints. I rarely get a
ConcurrentModificationException
exception which I guess is because the list is modified in the IO scope and read in the UI by compose. I read that one solution is to basically use a mutable state of an immutable list and assign a new list. That sounds a lot like I don't want to do this. Isn't there a better way to have a long list of datapoints that I can update from the IO thread?
And please don't refrain from telling me I'm a moron! I'm here for the fun and use every chance to learn. The tips I got from here already helped a lot and I could implement a live crypto chart that works amazingly fast even with 10k datapoints
k
This is a general #compose question, looks like
h
@Kirill Grouchnikov I thought because Jetpack compose has
ViewModel
the answer might not be applicable for desktop. That's why I asked here.
m
I think that problem can be solved by just using a persistent list from here: https://github.com/Kotlin/kotlinx.collections.immutable
m
Also note `mutableStateListOf()`is mostly a wrapper for
persistentListOf()
from the library above
K 1
h
Alright, thanks a lot. Let me look into this.