https://kotlinlang.org logo
#compose
Title
# compose
v

Vladimir Tagakov

10/27/2023, 7:11 PM
Hi folks! Can you help me to find a thing from google’s docs for compose? I am pretty sure I saw that google recommends to pass multiple callbacks to a composable function instead of using a single one with an action passed as a parameter. In other words they suggest to write:
Copy code
@Composable 
fun MyComposable(somethingHappened: () -> Unit, otherHappened: () -> Unit)
instead of
Copy code
@Composable
fun MyComposable(onAction: (ActionSealedClass) -> Unit)
Can’t find a proof for that in the docs or guidelines tho 😞 Can anyone help?
z

Zach Klippenstein (he/him) [MOD]

10/27/2023, 7:12 PM
I don’t think i’ve ever seen/heard this recommendation
a

agrosner

10/27/2023, 7:38 PM
im guessing its in the context of state and instead of passing
MutableState
as parameters, pairing it with callback and value as separate params:
Copy code
@Composable
fun MyComposable(value: ActionSealedClass,onUpdate: (ActionSealedClass) -> Unit)
https://developer.android.com/jetpack/compose/state#state-hoisting
v

Vladimir Tagakov

10/27/2023, 7:40 PM
Nope, that’s not the case 😞 Alright, I can’t find anything related, so I think it is either phantom memory or a change in the docs. Thank you, folks!
Nothing clear there.
v

Vladimir Tagakov

10/27/2023, 7:41 PM
Yep, they don’t mention anything like that
And also for some reason I can’t see the history of those files
a

Arkadii Ivanov

10/27/2023, 8:50 PM
There is "History" button at the bottom of the page. Does it help?
v

Vladimir Tagakov

10/27/2023, 8:52 PM
=\ I was lookig here: https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md And didn’t notice that Yuri’s link is to
<http://cs.android.com|cs.android.com>
instead. I’ll take a look, thank you, but I doubt I’ll be able to find it still :)
👍 1
It didn’t help 😞
😑 1
d

dewildte

10/27/2023, 9:32 PM
I swear I have seen the same advice somewhere too. Not sure if it showed up in a code workshop or what. But it did say to favor multiple lambdas over sealed classes and enums. I think the reasoning has to do with it being easier to refactor and implement thanks to it's simplicity.
4 Views