New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Data layer codelab] Section 7 (Create the task repository) should reuse mapped data #994
Comments
I think it should use the suspend fun refresh() {
val networkTasks = networkDataSource.loadTasks()
localDataSource.deleteAll()
val localTasks = withContext(dispatcher) {
networkTasks.toLocal()
}
localDataSource.upsertAll(localTasks) // Fixed this line
} |
I got this problem and I fixed this another way! override suspend fun upsertAll(tasks: List<LocalTask>) {
val newTaskIds = tasks.map { it.id }
_tasks.removeIf { newTaskIds.contains(it.id) }
_tasks.addAll(tasks)
tasksStream.emit(tasks) // this line
} I think this solution is a little bit better, because the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here:
suspend fun refresh() { val networkTasks = networkDataSource.loadTasks() localDataSource.deleteAll() val localTasks = withContext(dispatcher) { networkTasks.toLocal() } localDataSource.upsertAll(networkTasks.toLocal()) }
The last line should probably read:
localDataSource.upsertAll(networkTasks.toLocal())
The text was updated successfully, but these errors were encountered: