dimsuz
09/15/2022, 12:16 PMMyComposable(state, onClick = { someObject.sendEvent() })
and state is immutable, but someObject is not `Stable`/`Immutable`, (for example it can be a ViewModel or Presenter) this leads to constant recompositions, because onClick is not considered a Stable lambda. I confirmed this: my code stops constantly recomposing MyComposable if I make onClick empty.
What is the recommended refactoring to avoid such issues? Marking someObject as Stable is not always possible or often incorrect.ephemient
09/15/2022, 12:19 PMdimsuz
09/15/2022, 12:28 PMdimsuz
09/15/2022, 12:29 PMZoltan Demant
09/15/2022, 1:04 PM(Event) -> Unit callback for every state it produces. The lambda encapsulates some repository which is unstable. So the lambda is now unstable as well? 🤔dimsuz
09/15/2022, 1:11 PMclass SomeLambda(val viewModel: ViewModel) {
fun invoke() {
viewModel.callback(event)
}
}
if you have something like this, then repostitory will not be a property of SomeLambda class, so it will not pariticipate in compose's desicion on wheter onClick: SomeLambda argument is stable or not.Zoltan Demant
09/15/2022, 1:29 PMephemient
09/15/2022, 2:01 PMZoltan Demant
09/15/2022, 2:02 PM