'How to combine dialog prompt observables in a way that stops on the first deny

This is such a trivial thing to do with synchronous calls that it's driving me nuts how hard it seems to be to do. It also seems strange that a modal dialog returns an observable, but that's existing code and I need to understand why it should change before I change it and refactor other code.

Both of the approaches work but feel ugly and overblown to me, so I'm really hoping there's a better way to do this.

My instinctive approach:

keepGoing = true;

if (PromptCondition1True) { keepGoing = confirm("question 1") }

if (keepGoing && PromptCondition2True) { keepGoing = confirm("question 2") }

if (keepGoing) {
  this.doProcessing.process(processingRequest).subscribe();
}

Approach 1:

    iif(() => this.isDirty,
      defer(() => this.openConfirmDialog("Pending Updates", "There are changes that will be ignored for processing, do you want to process anyway? Cancel and press update to clear this warning")),
      of(true))
      .subscribe(result => {
        if (result === true) {
          return iif(() => this.selection.selected.some(x => !x.asdf.isActive),
            defer(() => this.openConfirmDialog("Inactive asdf", "Inactive asdf are selected for processing, do you want to continue?")),
            of(true))
            .subscribe(result => {
              if (result === true) {
                return this.doProcessing.process(processingRequest).subscribe();
              }
            });
        }
      });

Approach 2

    of(true).pipe(
      switchMap(() => iif(() => this.isDirty,
        defer(() => this.openConfirmDialog("Pending Updates", "There are changes that will be ignored for processing, do you want to process anyway? Cancel and press update to clear this warning")),
        of(true))),

      first(),
      filter(x => x === true),
      switchMap(() => iif(() => this.selection.selected.some(x => !x.asdf.isActive),
        defer(() => this.openConfirmDialog("Inactive asdf", "Inactive asdf are selected for processing, do you want to continue?")),
        of(true))),
      first(),
      filter(x => x === true),
      switchMap(() => this.doProcessing.process(processingRequest))).subscribe();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source