所以我有我的form模型,它包含我想要验证的所有数据,然后发送到服务器。让我们尽可能简单——isFormValid否则 api 请求应该返回Observable.errr(throwable)应该onError()在subscriber.
public void submitForm(Form form){
Observable
.just(form)
.flatMap(form->{
if(isFormValid(form))
return Observable.just(form);
else
return Observable.error(someValidationError);
})
.flatMap(form->{
Request req = new Request(form);
try{
return Observable.just(getResponseFrom(req));
}
catch(ApiException e){
return Observable.error(e)
}
}).subscribe(
new Subscriber<ResponseModel>(){
@Override
public void onComplete(){}
@Override
public void onError(Throwable t){}
@Override
public void onNext(ResponseModel model){}
}
);
}
好的,现在假设用户输入了无效数据,submitForm()被调用并 - 确定 -onError被调用subscriber,然后onComplete。然后用户输入有效数据并submitForm()再次被调用。
现在这是问题所在 - 在第二次submitForm()调用中没有任何反应!至少flatMap Func1和第二个flatMap Func2没有被调用。为什么?我究竟做错了什么 ?这是一个架构缺陷吗?