Skip to content
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

Using activeSurveyFlow to make flow async #2890

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anandwana001
Copy link
Collaborator

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 61.72%. Comparing base (9ab91bc) to head (222adf4).

Files with missing lines Patch % Lines
...round/ui/datacollection/DataCollectionViewModel.kt 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2890      +/-   ##
============================================
+ Coverage     61.68%   61.72%   +0.04%     
  Complexity     1173     1173              
============================================
  Files           268      268              
  Lines          6344     6349       +5     
  Branches        876      875       -1     
============================================
+ Hits           3913     3919       +6     
  Misses         1890     1890              
+ Partials        541      540       -1     
Files with missing lines Coverage Δ
...round/ui/datacollection/DataCollectionViewModel.kt 72.77% <85.71%> (+1.19%) ⬆️

@shobhitagarwal1612
Copy link
Member

shobhitagarwal1612 commented Dec 1, 2024

Won't this change now start failing to get the job as null?

@anandwana001
Copy link
Collaborator Author

Won't this change now start failing to get the job as survey is null?

Should we make the job as a flow too?

@shobhitagarwal1612
Copy link
Member

The question remains the same, will that pass on the error to the next item or will it stabilize the screen when survey is null?

@anandwana001
Copy link
Collaborator Author

The question remains the same, will that pass on the error to the next item or will it stabilize the screen when survey is null?

as the data collection screen is completely dependent on the activeSurvey, so in the worst case should we navigateUp or should we show some loading retry to fix the state flows and get the updated data?

@shobhitagarwal1612
Copy link
Member

should we show some loading retry to fix the state flows and get the updated data?

We shouldn't navigate up unless it's the last resort. Given that we know the survey id, we should try to make our sync code async and wait until it is ready.

val activeSurvey = _activeSurvey.asStateFlow()

init {
viewModelScope.launch { surveyRepository.activeSurveyFlow.collect { _activeSurvey.value = it } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't activeSurvey as you're defining it here functionally equivalent to surveyRepository.activeSurveyFlow? If so, why not just expose that instead?

private val activeSurvey: Survey = requireNotNull(surveyRepository.activeSurvey)
private val job: Job = activeSurvey.getJob(jobId) ?: error("couldn't retrieve job for $jobId")
private val _activeSurvey = MutableStateFlow<Survey?>(null)
val activeSurvey = _activeSurvey.asStateFlow()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean for this to be make public? I don't see a use anywhere else.

}

private val job: Job =
activeSurvey.value?.getJob(jobId) ?: error("couldn't retrieve job for $jobId")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling .value here will grab a snapshot of the current survey at the time this VM is initialized. How is that different from what we're doing already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[App Crash] activeSurvey is null
4 participants