Say i have a Composable which, makes use of `stri...
# compose
r
Say i have a Composable which, makes use of
stringResource
and maps from one object to another. I should be marking it as
@ReadOnlyComposable
? More in 🧵
Copy code
@Composable
@ReadOnlyComposable
fun SomeSealedClass.toOtherSealedClass(): OtherSealedClass {
  return when (this) {
    is SomeSealedClass.Something -> OtherSealedClass.Something(label = stringResource(id = this.stringId))
  }
}
Since this composable will never write to the composition, it can be marked as
ReadOnlyComposable
IMO, to avoid generating groups and all.
t
As I recall, a Composable that returns a value should not have a group.
Functions that have a non-unit return value don’t get their own scopes because they can’t be re-executed without also re-executing their caller, so their caller can “see” the new return value computed by the function.
https://dev.to/zachklipp/scoped-recomposition-jetpack-compose-what-happens-when-state-changes-l78
z
You never need to use these sorts of annotations. But yea if a composable returns a value then I don’t think this particular annotation has any effect anyway.
r
Ahh okay, but it will make compose runtime avoid generating groups and all on slot table? As it's not writing to a composition, generating things like those can be avoided, i believe.