Skip to content

Commit

Permalink
Use Flowable instead of Single on Middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak3125 committed Jan 2, 2018
1 parent 23061cd commit fab66df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import info.izumin.android.droidux.Action;
import info.izumin.android.droidux.Dispatcher;
import io.reactivex.Single;
import io.reactivex.Flowable;

/**
* Created by izumin on 11/29/15.
*/
public interface AsyncAction extends Action {
Single<Action> call(Dispatcher dispatcher);
Flowable<Action> call(Dispatcher dispatcher);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import info.izumin.android.droidux.Action;
import info.izumin.android.droidux.Middleware;
import io.reactivex.Single;
import io.reactivex.SingleSource;
import io.reactivex.Flowable;
import io.reactivex.functions.Function;

/**
Expand All @@ -13,27 +12,27 @@ public class ThunkMiddleware extends Middleware {
public static final String TAG = ThunkMiddleware.class.getSimpleName();

@Override
public Single<Action> beforeDispatch(final Action action) {
public Flowable<Action> beforeDispatch(final Action action) {
if (action instanceof AsyncAction) {
return ((AsyncAction) action).call(getDispatcher())
.flatMap(new Function<Action, SingleSource<? extends Action>>() {
.flatMap(new Function<Action, Flowable<? extends Action>>() {
@Override
public Single<Action> apply(Action next) throws Exception {
public Flowable<Action> apply(Action next) throws Exception {
return getDispatcher().dispatch(next);
}
})
.flatMap(new Function<Action, SingleSource<? extends Action>>() {
.flatMap(new Function<Action, Flowable<? extends Action>>() {
@Override
public Single<Action> apply(Action _next) throws Exception {
return Single.just(action);
public Flowable<Action> apply(Action _next) throws Exception {
return Flowable.just(action);
}
});
}
return Single.just(action);
return Flowable.just(action);
}

@Override
public Single<Action> afterDispatch(Action action) {
return Single.just(action);
public Flowable<Action> afterDispatch(Action action) {
return Flowable.just(action);
}
}

0 comments on commit fab66df

Please sign in to comment.