我正在尝试构建一个动态元流对象,等待某些流在 运行 之前完成
Im trying to build a dynamic meta stream object that waits for some of the streams to complete before running
The problem:
我有很多流馈入服务。单击按钮时,当前订阅其服务流的所有活动组件都会更新所述流。我需要遍历该服务中的所有流,并从不为空的流中构建一个 json 对象。
流服务
masterSubmit$: BehaviorSubject<string> = new BehaviorSubject(null);
addForm$: BehaviorSubject<model> = new BehaviorSubject(null);
addSubForm$: BehaviorSubject<otherModel> = new BehaviorSubject(null);
RxJSOperatorThatEmitsAllStreamsAtSameTime(
masterSubmit$,
addForm$,
addSubForm$,
).subscribe((data) => {
if(data[0] == null){
return;
}
if(data[1] != null){
jsonObject.properties = {data[1]}
}
etc..
if(data[0] == 'postNewThingy'){
this.apiStuff.postThingy(jsonObject);
}
})
这就是我想要的,任何建议都很棒!谢谢!
您好,您可以使用 combineLatest RXJS 运算符等待所有调用完成
combineLatest(masterSubmit$,
addForm$,
addSubForm$,).subscribe(
([masterSubmit, addForm, addSubForm]) => {
console.log(
`masterSubmit: ${masterSubmit},
addForm: ${addForm},
addSubForm: ${addSubForm}`
);
}
);
The problem:
我有很多流馈入服务。单击按钮时,当前订阅其服务流的所有活动组件都会更新所述流。我需要遍历该服务中的所有流,并从不为空的流中构建一个 json 对象。
流服务
masterSubmit$: BehaviorSubject<string> = new BehaviorSubject(null);
addForm$: BehaviorSubject<model> = new BehaviorSubject(null);
addSubForm$: BehaviorSubject<otherModel> = new BehaviorSubject(null);
RxJSOperatorThatEmitsAllStreamsAtSameTime(
masterSubmit$,
addForm$,
addSubForm$,
).subscribe((data) => {
if(data[0] == null){
return;
}
if(data[1] != null){
jsonObject.properties = {data[1]}
}
etc..
if(data[0] == 'postNewThingy'){
this.apiStuff.postThingy(jsonObject);
}
})
这就是我想要的,任何建议都很棒!谢谢!
您好,您可以使用 combineLatest RXJS 运算符等待所有调用完成
combineLatest(masterSubmit$,
addForm$,
addSubForm$,).subscribe(
([masterSubmit, addForm, addSubForm]) => {
console.log(
`masterSubmit: ${masterSubmit},
addForm: ${addForm},
addSubForm: ${addSubForm}`
);
}
);