简体   繁体   中英

Chain of observables with conditions

So I have 3 observables: updateCustomUserData$, updateEmail$, updatePassword$. And profileEditForm. I need to update profile data if appropriate fields of form was changed; I think it should look like this:

updateCustomUserData$(data) {
  return iif(() => customDataWasChanged(), apiService.updateCustomUserData())
}

// updateEmail$ and updatePassword$ is similar


onSubmit() {
  this.updateCustomUserData$(formData).pipe(
    concatMap(() => this.updateEmail$(newEmail))),
    concatMap(() => this.updatePassword$(newPassword),
  )
  .subscribe(() => doSomething())
}

But it is not working. If custom data was not changed and password or email do - updateEmail & updatePassword is not executing. Is anybody can help? PS Sorry for my English:)

When onSubmit method is called?
I think you should define ngOnInit instead of onSubmit.

export class AppComponent implements OnInit {
  ngOnInit() {
    this.updateCustomUserData$(formData).pipe(
      concatMap(() => this.updateEmail$(newEmail))),
      concatMap(() => this.updatePassword$(newPassword),
    )
    .subscribe(() => doSomething())  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM