Skip to content

[Code health] Simplify all the things #2289

@gino-m

Description

@gino-m

Nested calls to subscribe() in ngOnInit, mixing signals + observables, and inconsistent and/or duplicate source-of-truth, and loose separation of concerns have made many of the components hard to grok and maintain. For example:

ngOnInit(): void {
this.subscription.add(
this.navigationService.getSurveyId$().subscribe(async surveyId => {
this.surveyId = surveyId ? surveyId : NavigationService.SURVEY_ID_NEW;
this.surveyService.activateSurvey(this.surveyId);
await this.draftSurveyService.init(this.surveyId);
this.draftSurveyService
.getSurvey$()
.subscribe(survey => (this.survey = survey));
})
);
this.subscription.add(
combineLatest([
this.surveyService.getActiveSurvey$(),
this.loiService.getLocationsOfInterest$(),
])
.pipe(
filter(
([survey]) =>
this.surveyId === NavigationService.SURVEY_ID_NEW ||
survey.id === this.surveyId
)
)
.subscribe(([survey, lois]) => {
this.survey = survey;
if (this.isSetupFinished(this.survey)) {
this.navigationService.selectSurvey(this.survey.id);
}
this.lois = lois;
if (this.createSurveyPhase === CreateSurveyPhase.LOADING) {
this.createSurveyPhase = this.getSurveyPhase(survey, lois);
}
if (this.createSurveyPhase === CreateSurveyPhase.DEFINE_LOIS) {
this.canContinue =
!this.lois.isEmpty() ||
this.job()?.strategy === DataCollectionStrategy.MIXED;
}
})
);
}

Assigning this task to myself to come up with a plan to improve maintainability across the codebase.

@rfontanarosa FYI

Metadata

Metadata

Labels

type: code healthImprovements to readability or robustness of codebase

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions