RxjS shareReplay : how to reset its value?

后端 未结 4 543
醉梦人生
醉梦人生 2021-01-05 02:30

I use shareReplay to call only once (like a cache) a webservice to retrieve some informations :

In my service :

getProf         


        
4条回答
  •  青春惊慌失措
    2021-01-05 03:00

    Sounds like you can prepend a Subject that will inject the new value with merge:

    private refresh$ = new Subject();
    
    refreshProfile(...): void {
      this.refresh$.next(/* whatever */);
    }
    
    getProfile(): Observable {
      return this.callWS().pipe(
        merge(this.refresh$),
        shareReplay(1),
      );
    }
    

提交回复
热议问题