Hi. What is the best way to get a delegate from a ...
# announcements
a
Hi. What is the best way to get a delegate from a delegated property? I need it to wrap MutableStateFlow to a property delegate for my mini MVVM-framework. getDelegate requires kotlin.reflect package that is not optimal for Android development. I came up with this solution https://gist.github.com/aartikov/b64f462f50b5e5452c3df707db090a5f It uses a global (ThreadLocal to be more precise) holder to place a delegate there from getValue method. Do you have ideas how to implement it better?
d
What's wrong with just this?
Copy code
private val delegate = state(0)
val count by delegate
a
It requires two properties instead of one. It is inconvenient for view models that usually have a lot of properties.
d
Then you need to use
getDelegate
, no other way I can see
a
@diesieben07 what do you think about the solution from my gist?
d
I think it is absolutely disgusting 😄 And probably not very performant
🐷 1
a
Thank you for your opinion)