Cant access request value when using valueChanges inside forkJoin()

49 Views Asked by At

I`m using simple forkJoin() like this:

   const sources = [this.btApiClient.getAll(), this.buApiClient.getAll()];

forkJoin(sources)
  .pipe(
    map(([buildTypes, businessUnits]) => {

      this.bt$.next(buildTypes.result as GetAllBtsResponseItem[]);
      this.bu$.next(businessUnits.result as GetAllBusReponseItem[]);
    }),
    takeUntil(this.onDestroy$)
  ).subscribe()

So far so good.

But I want to add this one in the forkJoin as well:

this.tmSearcher.valueChanges.pipe(
  startWith(''),
  debounceTime(300),
  switchMap((searchStr) => {
    return this.npmApiClient.searchMember(searchStr ? searchStr : undefined, 100, 1, undefined, undefined);
  }),
  takeUntil(this.onDestroy$),
).subscribe(res => {
  this.teamMembers$.next(res!.result);
});

Basically I make new method which returns the above and just removing the subscribe() in the end like this:


    const sources = [this.btApiClient.getAll(), this.buApiClient.getAll(), this.Test1()];

    forkJoin(sources)
      .pipe(
        map(([buildTypes, businessUnits, tm]) => {

          this.bt$.next(buildTypes.result as GetAllBtsResponseItem[]);
          this.bu$.next(businessUnits.result as GetAllBusReponseItem[]);
        }),
        takeUntil(this.onDestroy$)
      ).subscribe()
  }

  private Test1() {
    return this.teamMembersSearcher.valueChanges.pipe(
      startWith(''),
      debounceTime(300),
      switchMap((searchStr) => {
        return this.npmApiClient.searchMember(searchStr ? searchStr : undefined, 100, 1, undefined, undefined);
      }),
      takeUntil(this.onDestroy$),
    )

When it is like this it makes the 3 HTTP request but it doesn even enter the map() and I cant assign values to variables. Neither it get to subscribe()

0

There are 0 best solutions below