【发布时间】:2021-06-13 05:31:46
【问题描述】:
我对 Firebase 数据库进行了以下调用。如果我想分享 observable 的结果,我应该把分享放在哪里(1)?
get userStacks(): Observable<StackModel[]> {
return this.auth.authState
.pipe(
shareReplay(1), ===>>> HERE ?
switchMap(user => {
if (user) {
return this.db
.collection<StackModel>('stacks', ref =>
ref.where('perm.readers', 'array-contains', user.uid),
)
.valueChanges()
.pipe(shareReplay(1), ===>>> HERE ?
stackList =>
combineLatest([
stackList,
this.dataService.currentNormalOrReverse,
this.idsFilter$,
]).pipe(
shareReplay(1), ===>>> HERE ?
map(([stacks, normalOrReverse]) => [
...StacksService.sortAlphabetical(stacks, normalOrReverse),
]),
),
);
}
return [];
}),
)
.pipe(shareReplay(1)), ===>>> HERE?
}
我想它应该是链中的最后一个操作,就在我订阅 observable 之前,因此它应该是这里的最后一个。我的假设正确吗?谢谢。
【问题讨论】:
标签: google-cloud-firestore rxjs observable angularfire rxjs-pipeable-operators