DEV Community

Discussion on: Plumbing data with derived state in Compose

Collapse
 
easetheworld profile image
EaseTheWorld • Edited

Thank you for amazing post. I have a question about derivedState.
To understand more, I made a Conway Game of life with compose.
github.com/EaseTheWorld/game_of_li...
Which is simply,

  • Each cell is State<Boolean>
  • Cell of root gen(0) is MutableState<Boolean>. It is toggled by user click.
  • Cell of child gen(1,2,3...) are DerivedState<Boolean> of prev gen's 9 cells.

When I put one cell alive in gen0, I expected only gen1 is recalculated and gen2,3,4... are not
because their prev is caching and unchanged.(still dead)
But it turns out gen2,3,4... are all recalculated. I put log in ChildCell.calculate()

Did I miss something about caching logic in DerivedState?

I ran your WorksheetImpl in android emulator(Pixel 5 API 29) and got same behavior.
I changed first row from 31.50 to 31.5 and expected no calculation for later rows.
but evalResult is recalculated for each rows...

Any reply would be very helpful.