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
diesieben07
01/14/2021, 11:25 AM
What's wrong with just this?
Copy code
private val delegate = state(0)
val count by delegate
a
Arthur Artikov
01/14/2021, 11:31 AM
It requires two properties instead of one. It is inconvenient for view models that usually have a lot of properties.
d
diesieben07
01/14/2021, 11:37 AM
Then you need to use
getDelegate
, no other way I can see
a
Arthur Artikov
01/14/2021, 11:39 AM
@diesieben07 what do you think about the solution from my gist?
d
diesieben07
01/14/2021, 11:40 AM
I think it is absolutely disgusting 😄 And probably not very performant