Teo Vladusic
02/05/2024, 2:16 PMJoel Denke
02/05/2024, 2:35 PMTeo Vladusic
02/05/2024, 2:40 PMval navController = appState.navController
NavHost(
navController = navController,
startDestination = startDestination,
modifier = modifier,
) {
forYouScreen(onTopicClick = navController::navigateToTopic)
bookmarksScreen(
onTopicClick = navController::navigateToTopic,
onShowSnackbar = onShowSnackbar,
)
searchScreen(
onBackClick = navController::popBackStack,
onInterestsClick = { appState.navigateToTopLevelDestination(INTERESTS) },
onTopicClick = navController::navigateToTopic,
)
interestsGraph(
onTopicClick = navController::navigateToTopic,
nestedGraphs = {
topicScreen(
onBackClick = navController::popBackStack,
onTopicClick = navController::navigateToTopic,
)
},
)
}
Joel Denke
02/05/2024, 2:46 PMstreetsofboston
02/05/2024, 2:48 PMsuspend
call/fun in your repo-class, service-class is the way to go (your viewmodel should 'merge' the results of these cals into a flow that your UI can then subscribe to)
Networking/business-logic results: In a sum-type, yes. Like Either
or Result
Be sure to have your viewmodel emit only 'plain' values to your UI, so that unwrapping them does not become a concern of your ui code.
Single or mutiple state vars: it depends 🙂
Ideally, single, but sometimes multiple is just a bit easier to handle in your code. Bundle discrete sets of UIs in logical and (quite independent) chunks and have a single state var to each of them.
Init or lifecycle for fetching: Depends; i prefer in lifecycle changes (eg when into STARTED state). Still be sure to initialize your initial state correctly, the state before any data is fetched.
VM navigation or callbacks: No opinion 🙂Teo Vladusic
02/05/2024, 2:49 PMJoel Denke
02/05/2024, 2:52 PMJoel Denke
02/05/2024, 2:54 PMstreetsofboston
02/05/2024, 3:00 PMviewmodelScope { launch { uiStateFlow.value = suspendDataFetch(input); }}
It is indeed a bit more work, but if using a Flow is done because the UI subscribes to Flows, it's putting a concern of one layer (UI) into a another layer (Data/Repo)
Also, calling sequential suspend funs reads better, imo, than chaining flows using lambdas, more imperative 🙂streetsofboston
02/05/2024, 3:01 PMJoel Denke
02/05/2024, 3:02 PMstreetsofboston
02/05/2024, 3:09 PMdewildte
02/05/2024, 6:51 PMdewildte
02/05/2024, 6:55 PM