I send a form using complex logic inside concatMap operator. And all works fine, but in my subscribe method I have additional http requests, which fires 2 times instead of 1. I tried to use takeLast operator, but it didn't help. I need to make requests in subscribe method only after all requests completed in concatMap.
For example, if I have two updateMember() events, after each request I get invoked function from subscribe method.
makeRequest(value) {
const team = toFormData(this.form.controls.profile.value);
this.teamService
.sendTeam(team)
.pipe(
concatMap(() => {
const tasks$ = [];
for (const [index, m] of this.form.controls.members.value.entries()) {
const member = toFormData(m);
if (m.id) {
tasks$.push(this.teamService.updateMember(member, m.id).pipe(take(1)));
} else if (!member.entries().next().done) {
if (member.has('name')) {
tasks$.push(this.teamService.createMember(member).pipe(take(1)));
} else {
(this.form.controls.members as FormArray).controls[index].markAllAsTouched();
this.scrollToFirstInvalidControl();
}
}
}
return tasks$.length ? concat(...tasks$) : EMPTY;
}),
)
.subscribe(() => {
this.teamService.getMembers().subscribe();
});
}
What should I use to make only necessary requests?