Created
November 14, 2019 12:53
-
-
Save manuelvicnt/0f687f1f1692f95b1b7b809674f68319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
class DefaultSessionAndUserEventRepository( | |
private val userEventDataSource: UserEventDataSource, | |
private val sessionRepository: SessionRepository | |
) : SessionAndUserEventRepository { | |
override fun getObservableUserEvent( | |
userId: String?, | |
eventId: SessionId | |
): Flow<Result<LoadUserSessionUseCaseResult>> { | |
// Handles null userId | |
// Observes the user events and merges them with session data | |
return userEventDataSource.getObservableUserEvent(userId, eventId).map { userEventResult -> | |
// lambda of the map operator that can call suspend functions | |
val event = sessionRepository.getSession(eventId) | |
// Merges session with user data and emits the result | |
val userSession = UserSession( | |
event, | |
userEventResult.userEvent ?: createDefaultUserEvent(event) | |
) | |
Result.Success(LoadUserSessionUseCaseResult(userSession)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ViewModel