Having a *formatter class* that is *expensive to i...
# compose
a
Having a formatter class that is expensive to instantiate but the function
fun format(number: Int): String
it uses then is side-effect free. Where would you use it with Compose? In the ViewModel and expose the State as String or in Compose? I intuitively would expose the number as state - and see the formatting as part of transforming the state to UI - so put it into the Compose part. How would you then get this class in Compose - if for performance reasons I’d usually inject it as
@Singleton
or
@Reusable
via dagger?
b
I think you can use any common Singleton pattern for this? If it's so slow you want to show a loading indicator in the UI, you can use coroutines to instantiate the singleton, and
produceState
to load it into Compose
🙌 1