hua*_*eng 4 angular rxjs6 rxjs-observables
我有一个场景,比如我需要在单击文件时获取文件内容。我想用 缓存文件内容 API shareReplay(),如何实现?
fileService.getContent是一个 API 服务,它将通过以下方式获取内容params(repository_id, filePath);
问题:
shareReplay() pipe?内部 API 服务?或者我在下面写的地方。shareReplay()仅调用一次。成分
fileOpened$ = new Subject();
...
this.fileOpened$.pipe(
switchMap(file => this.fileService.getContent(this.repository_id, file.filePath)),
shareReplay(1)
);
Run Code Online (Sandbox Code Playgroud)
服务:
getContent(repoId: string, path: string): Observable<string> {
return this.http.get<string>(
`/api/xxx/${repoId}/files/${decodeURIComponent(path)}`,
{
responseType: 'text' as 'json'
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4662 次 |
| 最近记录: |