Does it have any performance impact for passing the click events via interface (onClick: ClickListener) vs passing as lambda ( {} ->Unit in composable function parameters ?
d
dewildte
08/02/2023, 7:40 PM
I would not think so.
() -> Unit
is (basically) an interface.
👍 1
dewildte
08/02/2023, 7:42 PM
It’s almost like syntactic sugar for this:
fun interface Invokable<T> { operator fun invoke(): T }
dewildte
08/02/2023, 7:43 PM
Try making a
class
implement
() -> Unit
as an interface and you get almost the same thing.
s
subashz
08/02/2023, 7:47 PM
Copy code
what about something like this
interface OnPostEvent {
fun onClick(post:Data)
fun onLikePost(post:Data)
fun onDeletePost(post:Data)
}
@Composable
fun Post(clickEvent: OnPostEvent) {
// events
}
VS
@Composable
fun Post(onClick:(Data)->Unit, onLike:(Data)->Unit, onDelete:(Data) ->Unit) {
}
subashz
08/02/2023, 7:48 PM
@dewildte is that also same for above use-case ?
d
dewildte
08/02/2023, 8:01 PM
I know the bottom one is the recommended way to go.
It is more flexible and reduces the amount of boilerplate needed.