Exploring App Architecture
In Chapter 6, Building a Real-World App, we combined several key techniques of Jetpack Compose, including state hoisting, app theming, and navigation, in a real-world example. ComposeUnitConverter
stores state in a ViewModel
and eventually persists it using the Repository pattern. In this chapter, I will show you how to pass objects to a ViewModel
upon instantiation and use these objects to load and save data. In Chapter 2, Exploring the Key Principles of Compose, we examined features of well-behaved composable functions. Composables should be free of side effects to make them reusable and easy to test. However, there are situations when you need to either react to or initiate state changes that happen outside the scope of a composable function. We will cover this at the end of this chapter.
These are the main sections of this chapter:
- Persisting and retrieving state
- Keeping your composables responsive
- Understanding side effects