-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MVI - retry intents #214
Comments
Hm, haven't thought about it too much yet, but I could think of the following solution: class MyViewState {
String id;
Throwable error;
// ...
} The rest really depends on how you prefer to model your intents. interface MyView {
Observable<String> loadDataIntent(); // Fires in activity.onResume() for example
Observable<String> retryLoadingIntent() // Fires when retry button clicked
}
class MyPresenter extends MviBasePresenter {
protected void bindIntents(){
Observable<String> loadIntent = intent(MyView::loadIntent);
Observable<String> retryIntent = intent(MyView::retryLoadingIntent);
Observable<String> merged = Observable.merge(loaodingIntent, retryIntent);
Observable<MyViewState> vs = merged.flatMap(
id -> interactor.load(id)
.onErrorRetrurn( error -> new MyViewState(error, id) )
...
);
subscribeViewState(vs, MyView::render);
}
} Or you could already do the merging of both observables in the View Layer like this: class MyViewAcitiyt extends MviActivity<MyView, MyViewState> implements MyView {
PublishSubject<String> loadSubject = ... ; // i.e. fires in onResume()
PublisSubject<String> retrySubject = ... ; // fires on retry Button click
...
@Override
public Observable<String> loadIntent(){
return Observable.merge(loadSubject, retrySubject);
}
} I tend to prefer the first option because it is more explicit about the existence of a retry mechanism: I just have to look at the view interface to know what the view can actually do. It's just a matter of personal preference I guess. P.S. Docs for btw. could you please post this question on stackoverflow too (and any further questions)? Because github is really bad to be indexed by search engines like google. I'm sure other will have this question too soon or later. Definitely more discoverable if it is put on stackoverflow (There is a Mosby tag on github). |
Thanks @sockeqwe , actually I resolved the issue using class MyViewAcitiyt extends MviActivity<MyView, MyViewState> implements MyView {
PublishSubject<Boolean> retrySubject = ... ; // fires on retry Button click
...
@Override
public Observable<String> searchIntent(){
Observable<String> searchObservable = RxSearchView.queryTextChanges(searchView);
return Observable.combineLatest(searchObservable, retrySubject, (searchString, retryClicked) -> searchString);
}
} There is one thing to notice. @Override
protected void onStart() {
super.onStart();
retrySubject.onNext(true);
} I will share this and additional questions like this on StackOverflow in the future. |
I'm using the Mosby MVI library for a demo app that performs simple CRUD operations on a Restful API using Retrofit2 in my
Interactor
.I constructed the ViewStates very similar as in the sample App, containing
Throwable
when Retrofit responds with an error. In this case therender()
function displays an error screen with a retry button.When the retry button is clicked I want to re-emit the last item for the
Intent
that failed.I would like to do add something like
retryWhen()
to theIntent
, which of course is only triggered byonError()
Is there a simple way of adding this kind of behavior?
The text was updated successfully, but these errors were encountered: