Skip to content

Instantly share code, notes, and snippets.

@mattmook
Created September 1, 2021 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmook/f3e2be9deba94c48cd98a71a54b8fcde to your computer and use it in GitHub Desktop.
Save mattmook/f3e2be9deba94c48cd98a71a54b8fcde to your computer and use it in GitHub Desktop.
class PostListViewModel(
private val postRepository: PostRepository,
) : ViewModel(), ContainerHost<PostListState, NavigationEvent> {
override val container = viewModelScope.container<PostListState, NavigationEvent>(
initialState = PostListState()
) {
loadOverviews()
}
private fun loadOverviews() = intent {
val overviews = postRepository.getOverviews()
reduce {
state.copy(overviews = overviews)
}
}
fun onPostClicked(post: PostOverview) = intent {
postSideEffect(OpenPostNavigationEvent(post))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment