airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.83k stars 500 forks source link

Exploration of the correct way to update state with List<Data> in state #696

Closed artillerymans closed 1 year ago

artillerymans commented 1 year ago

中文: XXState中我定义了List如果我只想改变List中的任意一个XXXData的数据(假设我现在改变了任意一个XXXData中的name),这个时候都使用copy的方式会不会消耗的性能有点大了,我现在是在Jetpack Compose中使用,这个疑问一直在阻碍我去使用它。 En: I have defined List in XXState and if I just want to change the data of any XXXData in the List (assuming I change the name in any XXXData now), will it consume a bit too much performance if I use copy at this time, I am using it in Jetpack Compose now, and this query has been preventing me to use it.

gpeal commented 1 year ago

Copying/mapping a list is quite cheap on phones these days. That is the recommended approach with Mavericks. Mutability opens up the doors for a whole host of bugs that Mavericks tries to avoid.