gpt4 book ai didi

Angular pass result of observable through pipe(可观察到的贯穿管的角度通过结果)

转载 作者:bug小助手 更新时间:2023-10-25 17:53:35 27 4
gpt4 key购买 nike



I am trying to combine few observables and passing the value from first one through the entire pipe.

我正在尝试组合几个可观测的变量,并将第一个变量的值传递到整个管道。


this.auth.user
.pipe(
switchMap((authUser) => {
if (!authUser) {
return of();
}

const docRef = doc(this.firestore, firebaseCollections.UsersCollection, authUser.uid);
return from(getDoc(docRef));
}),
map((user)=>{
if(user){
return true;
}
return false
}),
switchMap([authUser, exists])={

}
)

On the last switchMap I would like to get the authUser from the from the first **switchMap ** but also the value from the map. I know I've done it in the past put can't find the solution anymore.

在最后一个SwitchMap上,我希望从第一个**SwitchMap**中获取authUser,同时也从map中获取值。我知道我已经做过了,现在已经找不到解决的办法了。


I guess it should be something like this but not sure witch rxjs functions should I use:

我猜应该是这样的,但不确定我应该使用哪个rxjs函数:


1: (authUser) => getFirestoreUser(authUser)

1:(AuthUser)=>getFirestore User(AuthUser)


2: (authUser, firestoreUser) => {...}

2:(authUser,FireStoreUser)=>{...}


更多回答
优秀答案推荐

I'm not a expertice in rxjs, but I feel you need "map" your intermediate response. Some like

我不是rxjs方面的专家,但我觉得您需要“映射”您的中间响应。有些人喜欢


this.auth.user
.pipe(
switchMap((authUser) => {
if (!authUser) {
return of([null,null] as [any,any]);
}
const docRef = doc(this.firestore, firebaseCollections.UsersCollection, authUser.uid);
//see that you use here pipe(map) to return an array
return from(getDoc(docRef)).pipe(
map((x:any)=>[x,authUser] as [any,any])
);
}),
map([user,authUser]:[any,any])=>{
if(user){
return [authUser,true] as [any,boolean];
}
return [authUser,false] as [any,boolean]
}),
switchMap([authUser, exists]:[any,boolean])={

}
)

NOTE: I use the "as [any:any]" to keep the type of the users

注意:我使用“as[any:any]”来保持用户的类型


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com