原谅尴尬的问题标题,我不确定该如何表达...
我有一个观察对象,它返回一个Form
对象。
export class QuestionConfiguration {
//...
}
export class Question {
configure(qc: QuestionConfiguration) {
// set variables...
};
}
export class Form {
constructor(public question: Question[]) {}
}
// lets assume this does a http call and returns an instanstiated list of forms.
let doFormsRequest$ = (): Observable<Forms[]> => {
}
还有另一种方法,它返回question
的每个内部Form.questions
的配置:
let getQuestionConfiguration$ = (question: Question): Observable<QuestionConfiguration> {
// ...
}
我希望创建一个ReplaySubject(1)
来作为可观察对象的观察者,该观察对象将每个问题配置为questionConfiguration可观察对象,并且仅在所有子问题均已配置后才返回。
有什么方法可以通过管道/地图/第一个可观察到的方式返回完全配置的表单来实现这一目标?
类似:
// using this as an observer so the configuration logic only happens once.
let mySubject: Subject<Form[]> = new ReplaySubject(1);
doFormsRequest$().pipe(
someOperator((forms: Forms[]) => {
// returns the configured form after calling and modifying each question according to the output of the getQuestionConfiguration observable
// i.e. question.configure(qc: QuestionConfiguration);
})
).subscribe(mySubject);