Search code examples
javascriptangulartypescriptngrxngrx-store

Synchronously call the Effect of ngrx component store


We have two effect in ComponentStore of ngrx.

  readonly startAndUpdateProgress = this.effect<void>(
    (trigger$) => trigger$.pipe(
      exhaustMap(() =>
        this.numbersObservable.pipe(
          tapResponse({
            next: (progress) => this.updateIrisFileListProgress(progress),
            error: (error) => console.error(error)
          })
        )
      )
    )
  );

  readonly postFileToServer = this.effect((formData$: Observable<FormData>) => {
    return formData$.pipe(
      switchMap((formData) => {
        return this.schemaUploadSrvice.postFiles(formData).pipe(
        tapResponse(
          (response) => this.updateSchemaUploadServerResponse(),
          (error: HttpErrorResponse) => console.error(error),
        )
      )}),
      
    );
  });

I want to wait for startAndUpdateProgress to complete before calling postFileToServer. Is there any way to perform this synchronously.


Solution

  • You can invoke postFileToServer within the startAndUpdateProgress effect.