Skip to content

Instantly share code, notes, and snippets.

@dturner
Created December 13, 2022 11:11
Show Gist options
  • Save dturner/0fc802bb040f80af5b3f9a9fe577998a to your computer and use it in GitHub Desktop.
Save dturner/0fc802bb040f80af5b3f9a9fe577998a to your computer and use it in GitHub Desktop.
BookmarksViewModel - After adding domain layer
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
class BookmarksViewModel @Inject constructor(
getSaveableNewsResources: GetSaveableNewsResourcesUseCase
) : ViewModel() {
val feedState: StateFlow<NewsFeedUiState> = getSaveableNewsResources()
.map { newsResources ->
newsResources.filter(SaveableNewsResource::isSaved)
}
.map<List<SaveableNewsResource>, NewsFeedUiState>(NewsFeedUiState::Success)
.onStart { emit(Loading) }
.stateIn(...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment