From 142a4fadc7e1699d3133d5874fd1de74fb96ab02 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 14:08:48 +0900 Subject: [PATCH 01/20] Add RxJava2 dependency to cores --- build.gradle | 1 + droidux-processor/build.gradle | 1 + droidux/build.gradle | 1 + 3 files changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index f5a00b7..4dcc636 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,7 @@ ext { databindingLibraryVersion = '1.0-rc3' supportLibrariesVersion = '23.1.1' rxJavaVersion = '1.1.0' + rxJava2Version = '2.1.8' rxAndroidVersion = '1.0.1' spockCoreVersion = '1.0-groovy-2.4' cglibVersion = '2.2' diff --git a/droidux-processor/build.gradle b/droidux-processor/build.gradle index 902ed33..d20a654 100644 --- a/droidux-processor/build.gradle +++ b/droidux-processor/build.gradle @@ -20,6 +20,7 @@ dependencies { compile 'com.google.auto.service:auto-service:1.0-rc2' compile "io.reactivex:rxjava:${project.rxJavaVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" compile "com.android.databinding:baseLibrary:${project.databindingBaseLibraryVersion}" compile fileTree(dir: './libs', includes: ['*.jar']) diff --git a/droidux/build.gradle b/droidux/build.gradle index 61c8409..ba7608c 100644 --- a/droidux/build.gradle +++ b/droidux/build.gradle @@ -7,6 +7,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7 dependencies { compile "io.reactivex:rxjava:${project.rxJavaVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" testCompile "org.spockframework:spock-core:${project.spockCoreVersion}" testCompile "cglib:cglib-nodep:${project.cglibVersion}" From a1e9a62471a341445f4796f987710a56dc38191d Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 14:43:40 +0900 Subject: [PATCH 02/20] Migrate RxJava to RxJava2 for droidux core modules --- .../generator/StoreClassGenerator.java | 4 +- .../processor/model/StoreMethodModel.java | 4 +- droidux/build.gradle | 5 +-- .../izumin/android/droidux/BaseStore.java | 4 +- .../izumin/android/droidux/Dispatcher.java | 40 +++++++++---------- .../izumin/android/droidux/Middleware.java | 6 +-- .../izumin/android/droidux/StoreImpl.java | 13 ++++-- .../android/droidux/DispatcherTest.groovy | 10 ++--- .../android/droidux/thunk/AsyncAction.java | 4 +- .../droidux/thunk/ThunkMiddleware.java | 23 ++++++----- 10 files changed, 60 insertions(+), 53 deletions(-) diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java index d2565b3..e06f51a 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java @@ -26,7 +26,7 @@ import info.izumin.android.droidux.processor.model.StoreImplModel; import info.izumin.android.droidux.processor.model.StoreMethodModel; import info.izumin.android.droidux.processor.model.StoreModel; -import rx.Observable; +import io.reactivex.Single; import static info.izumin.android.droidux.processor.util.PoetUtils.getOverrideAnnotation; import static info.izumin.android.droidux.processor.util.PoetUtils.getParameterSpec; @@ -157,7 +157,7 @@ private MethodSpec createDispatchMethodSpec() { return MethodSpec.methodBuilder(StoreModel.DISPATCH_METHOD_NAME) .addAnnotation(getOverrideAnnotation()) .addModifiers(Modifier.PUBLIC) - .returns(ParameterizedTypeName.get(ClassName.get(Observable.class), ClassName.get(Action.class))) + .returns(ParameterizedTypeName.get(ClassName.get(Single.class), ClassName.get(Action.class))) .addParameter(getParameterSpec(Action.class)) .addStatement("return $N.$N($N)", DispatcherModel.VARIABLE_NAME, DispatcherModel.DISPATCH_METHOD_NAME, diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java index 5d9bd5e..e74b973 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java @@ -17,7 +17,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; -import rx.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/28/15. @@ -32,7 +32,7 @@ enum Kind { UNKNOWN } - private static final Class OBSERVE_METHOD_CLASS = Observable.class; + private static final Class OBSERVE_METHOD_CLASS = Flowable.class; private final ExecutableElement element; private final StoreModel storeModel; diff --git a/droidux/build.gradle b/droidux/build.gradle index ba7608c..82e6d16 100644 --- a/droidux/build.gradle +++ b/droidux/build.gradle @@ -2,11 +2,10 @@ apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'com.novoda.bintray-release' -targetCompatibility = JavaVersion.VERSION_1_7 -sourceCompatibility = JavaVersion.VERSION_1_7 +targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_1_8 dependencies { - compile "io.reactivex:rxjava:${project.rxJavaVersion}" compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" testCompile "org.spockframework:spock-core:${project.spockCoreVersion}" diff --git a/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java b/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java index caf7878..79efc87 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java +++ b/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java @@ -1,8 +1,10 @@ package info.izumin.android.droidux; +import io.reactivex.Single; + /** * Created by izumin on 12/6/15. */ public interface BaseStore { - rx.Observable dispatch(Action action); + Single dispatch(Action action); } diff --git a/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java b/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java index c3fac7a..3819388 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java +++ b/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java @@ -4,9 +4,10 @@ import java.util.List; import java.util.ListIterator; -import rx.Observable; -import rx.functions.Action1; -import rx.functions.Func1; +import io.reactivex.Single; +import io.reactivex.SingleSource; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Function; /** * Created by izumin on 11/28/15. @@ -22,37 +23,36 @@ public Dispatcher(List middlewares, StoreImpl... storeImpls) { this.storeImpls = Arrays.asList(storeImpls); } - public Observable dispatch(Action action) { - return Observable.just(action) - .flatMap(new Func1>() { + public Single dispatch(Action action) { + return Single.just(action) + .flatMap(new Function>() { @Override - public Observable call(Action action) { + public SingleSource apply(Action action) throws Exception { return applyMiddlewaresBeforeDispatch(action); } - }) - .doOnNext(new Action1() { + }).doOnSuccess(new Consumer() { @Override - public void call(Action action) { + public void accept(Action action) throws Exception { for (StoreImpl store : storeImpls) { store.dispatch(action); } } }) - .flatMap(new Func1>() { + .flatMap(new Function>() { @Override - public Observable call(Action action) { + public SingleSource apply(Action action) throws Exception { return applyMiddlewaresAfterDispatch(action); } }); } - private Observable applyMiddlewaresBeforeDispatch(Action action) { - Observable o = Observable.just(action); + private Single applyMiddlewaresBeforeDispatch(Action action) { + Single o = Single.just(action); for (final Middleware mw : middlewares) { - o = o.flatMap(new Func1>() { + o = o.flatMap(new Function>() { @Override - public Observable call(Action a) { + public Single apply(Action a) throws Exception { return mw.beforeDispatch(a); } }); @@ -60,14 +60,14 @@ public Observable call(Action a) { return o; } - private Observable applyMiddlewaresAfterDispatch(Action action) { - Observable o = Observable.just(action); + private Single applyMiddlewaresAfterDispatch(Action action) { + Single o = Single.just(action); ListIterator iterator = middlewares.listIterator(middlewares.size()); while(iterator.hasPrevious()) { final Middleware mw = iterator.previous(); - o = o.flatMap(new Func1>() { + o = o.flatMap(new Function>() { @Override - public Observable call(Action a) { + public Single apply(Action a) throws Exception { return mw.afterDispatch(a); } }); diff --git a/droidux/src/main/java/info/izumin/android/droidux/Middleware.java b/droidux/src/main/java/info/izumin/android/droidux/Middleware.java index 37c7dc1..d70a50f 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/Middleware.java +++ b/droidux/src/main/java/info/izumin/android/droidux/Middleware.java @@ -1,6 +1,6 @@ package info.izumin.android.droidux; -import rx.Observable; +import io.reactivex.Single; /** * Created by izumin on 11/2/15. @@ -24,6 +24,6 @@ protected Dispatcher getDispatcher() { return dispatcher; } - public abstract Observable beforeDispatch(Action action); - public abstract Observable afterDispatch(Action action); + public abstract Single beforeDispatch(Action action); + public abstract Single afterDispatch(Action action); } diff --git a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java index 5adb0a3..efed5fc 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java +++ b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java @@ -3,8 +3,9 @@ import java.util.HashSet; import java.util.Set; -import rx.Observable; -import rx.subjects.BehaviorSubject; +import io.reactivex.BackpressureStrategy; +import io.reactivex.Flowable; +import io.reactivex.subjects.BehaviorSubject; /** * Created by izumin on 11/2/15. @@ -24,8 +25,12 @@ protected StoreImpl(T state, R reducer) { listeners = new HashSet<>(); } - public Observable observe() { - return subject; + public Flowable observe() { + return observe(BackpressureStrategy.DROP); + } + + public Flowable observe(BackpressureStrategy strategy) { + return subject.toFlowable(strategy); } public T getState() { diff --git a/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy b/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy index 3f8fdd0..ff78565 100644 --- a/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy +++ b/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy @@ -1,6 +1,6 @@ package info.izumin.android.droidux -import rx.Observable +import io.reactivex.Single import spock.lang.Specification; /** @@ -34,10 +34,10 @@ class DispatcherTest extends Specification { dispatcher.dispatch(action).subscribe() then: - 1 * middleware1.beforeDispatch(action) >> Observable.just(action) + 1 * middleware1.beforeDispatch(action) >> Single.just(action) then: - 1 * middleware2.beforeDispatch(action) >> Observable.just(action) + 1 * middleware2.beforeDispatch(action) >> Single.just(action) then: 1 * store1.dispatch(action) @@ -46,9 +46,9 @@ class DispatcherTest extends Specification { 1 * store2.dispatch(action) then: - 1 * middleware2.afterDispatch(action) >> Observable.just(action) + 1 * middleware2.afterDispatch(action) >> Single.just(action) then: - 1 * middleware1.afterDispatch(action) >> Observable.just(action) + 1 * middleware1.afterDispatch(action) >> Single.just(action) } } diff --git a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java index 25add30..f4c4928 100644 --- a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java +++ b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java @@ -2,11 +2,11 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Dispatcher; -import rx.Observable; +import io.reactivex.Single; /** * Created by izumin on 11/29/15. */ public interface AsyncAction extends Action { - Observable call(Dispatcher dispatcher); + Single call(Dispatcher dispatcher); } diff --git a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java index a3c3f01..e7716ce 100644 --- a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java +++ b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java @@ -2,8 +2,9 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Middleware; -import rx.Observable; -import rx.functions.Func1; +import io.reactivex.Single; +import io.reactivex.SingleSource; +import io.reactivex.functions.Function; /** * Created by izumin on 11/29/15. @@ -12,27 +13,27 @@ public class ThunkMiddleware extends Middleware { public static final String TAG = ThunkMiddleware.class.getSimpleName(); @Override - public Observable beforeDispatch(final Action action) { + public Single beforeDispatch(final Action action) { if (action instanceof AsyncAction) { return ((AsyncAction) action).call(getDispatcher()) - .flatMap(new Func1>() { + .flatMap(new Function>() { @Override - public Observable call(Action next) { + public Single apply(Action next) throws Exception { return getDispatcher().dispatch(next); } }) - .flatMap(new Func1>() { + .flatMap(new Function>() { @Override - public Observable call(Action _next) { - return Observable.just(action); + public Single apply(Action _next) throws Exception { + return Single.just(action); } }); } - return Observable.just(action); + return Single.just(action); } @Override - public Observable afterDispatch(Action action) { - return Observable.just(action); + public Single afterDispatch(Action action) { + return Single.just(action); } } From 62c3e88caeb367d7b6c469e984ad333125cbaa48 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 20:30:15 +0900 Subject: [PATCH 03/20] Make compile passing --- .../processor/model/StoreMethodModel.java | 4 +- .../droidux/processor/fixture/Source.java | 14 +++--- droidux/build.gradle | 4 +- .../izumin/android/droidux/StoreImpl.java | 9 ++-- .../example/todomvc/MainActivityHelper.java | 31 ++++++------- .../droidux/example/todomvc/RootStore.java | 2 +- .../example/todomvc/middleware/Logger.java | 9 ++-- .../example/todoswithdagger/RootStore.java | 2 +- .../module/main/MainPresenter.java | 43 +++++++++---------- .../todoswithundo/MainActivityHelper.java | 31 ++++++------- .../example/todoswithundo/RootStore.java | 2 +- .../todoswithundo/middleware/Logger.java | 11 ++--- 12 files changed, 81 insertions(+), 81 deletions(-) diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java index e74b973..9eece08 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java @@ -17,7 +17,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; -import io.reactivex.Flowable; +import io.reactivex.Observable; /** * Created by izumin on 11/28/15. @@ -32,7 +32,7 @@ enum Kind { UNKNOWN } - private static final Class OBSERVE_METHOD_CLASS = Flowable.class; + private static final Class OBSERVE_METHOD_CLASS = Observable.class; private final ExecutableElement element; private final StoreModel storeModel; diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index 364e2d7..332a2ee 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -87,7 +87,7 @@ public static class Counter { "import info.izumin.android.droidux.BaseStore;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", - "import rx.Observable;", + "import io.reactivex.Observable;", "@Store({CounterReducer.class})", "public interface RootStore extends BaseStore {", " Counter counter();", @@ -107,7 +107,7 @@ public static class Counter { "import info.izumin.android.droidux.processor.fixture.CounterReducer;", "import java.util.ArrayList;", "import java.util.List;", - "import rx.Observable;", + "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -184,7 +184,7 @@ public static class BindableCounter { "import info.izumin.android.droidux.BaseStore;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", - "import rx.Observable;", + "import io.reactivex.Observable;", "@Store({CounterReducer.class})", "public interface RootStore extends BaseStore, android.databinding.Observable {", " @Bindable Counter counter();", @@ -205,7 +205,7 @@ public static class BindableCounter { "import info.izumin.android.droidux.processor.fixture.CounterReducer;", "import java.util.ArrayList;", "import java.util.List;", - "import rx.Observable;", + "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -315,7 +315,7 @@ public static class CombinedTwoReducers { "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", "import java.util.ArrayList;", "import java.util.List;", - "import rx.Observable;", + "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -421,7 +421,7 @@ public static class CombinedReducerAndBindableReducer { "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.TodoList;", - "import rx.Observable;", + "import io.reactivex.Observable;", "@Store({CounterReducer.class, TodoListReducer.class})", "public interface RootStore extends BaseStore, android.databinding.Observable {", " Counter counter();", @@ -446,7 +446,7 @@ public static class CombinedReducerAndBindableReducer { "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", "import java.util.ArrayList;", "import java.util.List;", - "import rx.Observable;", + "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", diff --git a/droidux/build.gradle b/droidux/build.gradle index 82e6d16..ef3bd26 100644 --- a/droidux/build.gradle +++ b/droidux/build.gradle @@ -2,8 +2,8 @@ apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'com.novoda.bintray-release' -targetCompatibility = JavaVersion.VERSION_1_8 -sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_7 +sourceCompatibility = JavaVersion.VERSION_1_7 dependencies { compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" diff --git a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java index efed5fc..94252d8 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java +++ b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java @@ -5,6 +5,7 @@ import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; +import io.reactivex.Observable; import io.reactivex.subjects.BehaviorSubject; /** @@ -25,12 +26,8 @@ protected StoreImpl(T state, R reducer) { listeners = new HashSet<>(); } - public Flowable observe() { - return observe(BackpressureStrategy.DROP); - } - - public Flowable observe(BackpressureStrategy strategy) { - return subject.toFlowable(strategy); + public Observable observe() { + return subject; } public T getState() { diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java index dc34c72..8b98002 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java @@ -11,9 +11,8 @@ import info.izumin.android.droidux.example.todomvc.action.ClearCompletedTodoAction; import info.izumin.android.droidux.example.todomvc.action.DeleteTodoAction; import info.izumin.android.droidux.example.todomvc.action.ToggleCompletedTodoAction; -import rx.Observable; -import rx.android.schedulers.AndroidSchedulers; -import rx.subjects.PublishSubject; +import io.reactivex.Single; +import io.reactivex.subjects.SingleSubject; /** * Created by izumin on 11/5/15. @@ -41,8 +40,9 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s))) - .subscribeOn(AndroidSchedulers.mainThread()) + .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { editNewTodo.setText(""); Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show(); @@ -54,7 +54,8 @@ public void onCreate() { observeOnLongClickListItem() .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) - .subscribeOn(AndroidSchedulers.mainThread()) + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show(); }); @@ -72,27 +73,27 @@ public boolean onOptionItemSelected(MenuItem item) { } } - private Observable observeOnClickBtnAddTodo() { - PublishSubject subject= PublishSubject.create(); - btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString())); + private Single observeOnClickBtnAddTodo() { + SingleSubject subject = SingleSubject.create(); + btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString())); return subject; } - private Observable observeOnClickListItem() { - PublishSubject subject = PublishSubject.create(); - listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id)); + private Single observeOnClickListItem() { + SingleSubject subject = SingleSubject.create(); + listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id)); return subject; } - private Observable observeOnLongClickListItem() { - PublishSubject subject = PublishSubject.create(); + private Single observeOnLongClickListItem() { + SingleSubject subject = SingleSubject.create(); listTodo.setOnItemLongClickListener((parent, view, position, id) -> { new AlertDialog.Builder(activity) .setTitle(R.string.dialog_delete_todo_title) .setMessage(activity.getString(R.string.dialog_delete_todo_message, store.todoList().getTodoById((int) id).getText())) .setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> { - subject.onNext(id); + subject.onSuccess(id); }) .setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> { dialog.dismiss(); diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java index 1617b7e..83c983f 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todomvc.entity.TodoList; import info.izumin.android.droidux.example.todomvc.reducer.TodoListReducer; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/29/15. diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java index d5593db..529d8d6 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java @@ -5,6 +5,7 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Middleware; import info.izumin.android.droidux.example.todomvc.RootStore; +import io.reactivex.Single; import rx.Observable; /** @@ -14,15 +15,15 @@ public class Logger extends Middleware { public static final String TAG = Logger.class.getSimpleName(); @Override - public Observable beforeDispatch(Action action) { + public Single beforeDispatch(Action action) { Log.d("[prev todo]", getStore().todoList().toString()); Log.d("[" + action.getClass().getSimpleName() + "]", action.toString()); - return Observable.just(action); + return Single.just(action); } @Override - public Observable afterDispatch(Action action) { + public Single afterDispatch(Action action) { Log.d("[next todo]", getStore().todoList().toString()); - return Observable.just(action); + return Single.just(action); } } diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java index da23b39..9c105e2 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; import info.izumin.android.droidux.example.todoswithdagger.reducer.TodoListReducer; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/29/15. diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java index 623f6ce..89cb814 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java @@ -7,9 +7,8 @@ import info.izumin.android.droidux.example.todoswithdagger.action.ClearNewTodoTextAction; import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction; -import rx.android.schedulers.AndroidSchedulers; -import rx.subjects.PublishSubject; -import rx.subscriptions.CompositeSubscription; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.subjects.SingleSubject; /** * Created by izumin on 11/5/15. @@ -20,11 +19,11 @@ public class MainPresenter { private final MainView view; private final RootStore store; - private final PublishSubject clickAddTodoSubject = PublishSubject.create(); - private final PublishSubject clickItemSubject = PublishSubject.create(); - private final PublishSubject longClickItemSubject = PublishSubject.create(); + private final SingleSubject clickAddTodoSubject = SingleSubject.create(); + private final SingleSubject clickItemSubject = SingleSubject.create(); + private final SingleSubject longClickItemSubject = SingleSubject.create(); - private CompositeSubscription subscriptions; + private CompositeDisposable compositeDisposable; public MainPresenter(MainView view, RootStore store) { this.view = view; @@ -32,44 +31,44 @@ public MainPresenter(MainView view, RootStore store) { } void onStart() { - subscriptions = new CompositeSubscription(); + compositeDisposable = new CompositeDisposable(); - subscriptions.add(clickAddTodoSubject + compositeDisposable.add(clickAddTodoSubject .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s))) - .subscribeOn(AndroidSchedulers.mainThread()) - .flatMap(_a -> store.dispatch(new ClearNewTodoTextAction())) + .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toMaybe()) .subscribe(_a -> { view.clearNewTodoText(); view.showToast(R.string.toast_add_todo); })); - subscriptions.add(clickItemSubject + compositeDisposable.add(clickItemSubject .flatMap(id -> store.dispatch(new ToggleCompletedTodoAction(id.intValue()))) .subscribe()); - subscriptions.add(longClickItemSubject + compositeDisposable.add(longClickItemSubject .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) - .subscribeOn(AndroidSchedulers.mainThread()) - .subscribe(action -> { - view.showToast(R.string.toast_delete_todo); - })); + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribe(action -> view.showToast(R.string.toast_delete_todo))); } void onStop() { - subscriptions.unsubscribe(); + compositeDisposable.clear(); } void onClickBtnAddTodo(String text) { - clickAddTodoSubject.onNext(text); + clickAddTodoSubject.onSuccess(text); } void onClickListItem(long id) { - clickItemSubject.onNext(id); + clickItemSubject.onSuccess(id); } void onLongClickListItem(long id) { - longClickItemSubject.onNext(id); + longClickItemSubject.onSuccess(id); } void clearCompletedTodo() { diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java index 55c6b2e..f20aaf7 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java @@ -14,9 +14,8 @@ import info.izumin.android.droidux.example.todoswithundo.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithundo.action.ToggleCompletedTodoAction; import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer; -import rx.Observable; -import rx.android.schedulers.AndroidSchedulers; -import rx.subjects.PublishSubject; +import io.reactivex.Single; +import io.reactivex.subjects.SingleSubject; /** * Created by izumin on 11/5/15. @@ -44,8 +43,9 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s))) - .subscribeOn(AndroidSchedulers.mainThread()) + .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { editNewTodo.setText(""); Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show(); @@ -57,7 +57,8 @@ public void onCreate() { observeOnLongClickListItem() .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) - .subscribeOn(AndroidSchedulers.mainThread()) + /*TODO: Version up RxAndroid*/ + /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show(); }); @@ -81,27 +82,27 @@ public boolean onOptionItemSelected(MenuItem item) { } } - private Observable observeOnClickBtnAddTodo() { - PublishSubject subject= PublishSubject.create(); - btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString())); + private io.reactivex.Single observeOnClickBtnAddTodo() { + SingleSubject subject = SingleSubject.create(); + btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString())); return subject; } - private Observable observeOnClickListItem() { - PublishSubject subject = PublishSubject.create(); - listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id)); + private io.reactivex.Single observeOnClickListItem() { + SingleSubject subject = SingleSubject.create(); + listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id)); return subject; } - private Observable observeOnLongClickListItem() { - PublishSubject subject = PublishSubject.create(); + private Single observeOnLongClickListItem() { + SingleSubject subject = SingleSubject.create(); listTodo.setOnItemLongClickListener((parent, view, position, id) -> { new AlertDialog.Builder(activity) .setTitle(R.string.dialog_delete_todo_title) .setMessage(activity.getString(R.string.dialog_delete_todo_message, store.todoList().getTodoById((int) id).getText())) .setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> { - subject.onNext(id); + subject.onSuccess(id); }) .setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> { dialog.dismiss(); diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java index 08a5721..88788ec 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todoswithundo.entity.TodoList; import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/29/15. diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java index 6a4980b..9d5d160 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java @@ -5,7 +5,7 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Middleware; import info.izumin.android.droidux.example.todoswithundo.RootStore; -import rx.Observable; +import io.reactivex.Single; /** * Created by izumin on 11/4/15. @@ -13,16 +13,17 @@ public class Logger extends Middleware { public static final String TAG = Logger.class.getSimpleName(); + @Override - public Observable beforeDispatch(Action action) { + public Single beforeDispatch(Action action) { Log.d("[prev todo]", getStore().todoList().toString()); Log.d("[" + action.getClass().getSimpleName() + "]", action.toString()); - return Observable.just(action); + return Single.just(action); } @Override - public Observable afterDispatch(Action action) { + public Single afterDispatch(Action action) { Log.d("[next todo]", getStore().todoList().toString()); - return Observable.just(action); + return Single.just(action); } } From 23061cd21b479aa01546cbee81806402d04410e4 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 21:23:43 +0900 Subject: [PATCH 04/20] Use Flowable instead of Single --- .../processor/model/StoreMethodModel.java | 4 +-- .../izumin/android/droidux/BaseStore.java | 3 +- .../izumin/android/droidux/Dispatcher.java | 33 +++++++++---------- .../izumin/android/droidux/Middleware.java | 6 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java index 9eece08..e74b973 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java @@ -17,7 +17,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; -import io.reactivex.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/28/15. @@ -32,7 +32,7 @@ enum Kind { UNKNOWN } - private static final Class OBSERVE_METHOD_CLASS = Observable.class; + private static final Class OBSERVE_METHOD_CLASS = Flowable.class; private final ExecutableElement element; private final StoreModel storeModel; diff --git a/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java b/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java index 79efc87..591deb8 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java +++ b/droidux/src/main/java/info/izumin/android/droidux/BaseStore.java @@ -1,10 +1,11 @@ package info.izumin.android.droidux; +import io.reactivex.Flowable; import io.reactivex.Single; /** * Created by izumin on 12/6/15. */ public interface BaseStore { - Single dispatch(Action action); + Flowable dispatch(Action action); } diff --git a/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java b/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java index 3819388..c99beca 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java +++ b/droidux/src/main/java/info/izumin/android/droidux/Dispatcher.java @@ -4,8 +4,7 @@ import java.util.List; import java.util.ListIterator; -import io.reactivex.Single; -import io.reactivex.SingleSource; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; import io.reactivex.functions.Function; @@ -23,14 +22,14 @@ public Dispatcher(List middlewares, StoreImpl... storeImpls) { this.storeImpls = Arrays.asList(storeImpls); } - public Single dispatch(Action action) { - return Single.just(action) - .flatMap(new Function>() { + public Flowable dispatch(Action action) { + return Flowable.just(action) + .flatMap(new Function>() { @Override - public SingleSource apply(Action action) throws Exception { + public Flowable apply(Action action) throws Exception { return applyMiddlewaresBeforeDispatch(action); } - }).doOnSuccess(new Consumer() { + }).doOnNext(new Consumer() { @Override public void accept(Action action) throws Exception { for (StoreImpl store : storeImpls) { @@ -38,21 +37,21 @@ public void accept(Action action) throws Exception { } } }) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public SingleSource apply(Action action) throws Exception { + public Flowable apply(Action action) throws Exception { return applyMiddlewaresAfterDispatch(action); } }); } - private Single applyMiddlewaresBeforeDispatch(Action action) { - Single o = Single.just(action); + private Flowable applyMiddlewaresBeforeDispatch(Action action) { + Flowable o = Flowable.just(action); for (final Middleware mw : middlewares) { - o = o.flatMap(new Function>() { + o = o.flatMap(new Function>() { @Override - public Single apply(Action a) throws Exception { + public Flowable apply(Action a) throws Exception { return mw.beforeDispatch(a); } }); @@ -60,14 +59,14 @@ public Single apply(Action a) throws Exception { return o; } - private Single applyMiddlewaresAfterDispatch(Action action) { - Single o = Single.just(action); + private Flowable applyMiddlewaresAfterDispatch(Action action) { + Flowable o = Flowable.just(action); ListIterator iterator = middlewares.listIterator(middlewares.size()); while(iterator.hasPrevious()) { final Middleware mw = iterator.previous(); - o = o.flatMap(new Function>() { + o = o.flatMap(new Function>() { @Override - public Single apply(Action a) throws Exception { + public Flowable apply(Action a) throws Exception { return mw.afterDispatch(a); } }); diff --git a/droidux/src/main/java/info/izumin/android/droidux/Middleware.java b/droidux/src/main/java/info/izumin/android/droidux/Middleware.java index d70a50f..be3f23f 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/Middleware.java +++ b/droidux/src/main/java/info/izumin/android/droidux/Middleware.java @@ -1,6 +1,6 @@ package info.izumin.android.droidux; -import io.reactivex.Single; +import io.reactivex.Flowable; /** * Created by izumin on 11/2/15. @@ -24,6 +24,6 @@ protected Dispatcher getDispatcher() { return dispatcher; } - public abstract Single beforeDispatch(Action action); - public abstract Single afterDispatch(Action action); + public abstract Flowable beforeDispatch(Action action); + public abstract Flowable afterDispatch(Action action); } From fab66df425868216e26b6cbd1cd0d900dd781036 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 21:26:05 +0900 Subject: [PATCH 05/20] Use Flowable instead of Single on Middleware --- .../android/droidux/thunk/AsyncAction.java | 4 ++-- .../droidux/thunk/ThunkMiddleware.java | 21 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java index f4c4928..26650fa 100644 --- a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java +++ b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/AsyncAction.java @@ -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 call(Dispatcher dispatcher); + Flowable call(Dispatcher dispatcher); } diff --git a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java index e7716ce..970d391 100644 --- a/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java +++ b/middlewares/droidux-thunk/src/main/java/info/izumin/android/droidux/thunk/ThunkMiddleware.java @@ -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; /** @@ -13,27 +12,27 @@ public class ThunkMiddleware extends Middleware { public static final String TAG = ThunkMiddleware.class.getSimpleName(); @Override - public Single beforeDispatch(final Action action) { + public Flowable beforeDispatch(final Action action) { if (action instanceof AsyncAction) { return ((AsyncAction) action).call(getDispatcher()) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Single apply(Action next) throws Exception { + public Flowable apply(Action next) throws Exception { return getDispatcher().dispatch(next); } }) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Single apply(Action _next) throws Exception { - return Single.just(action); + public Flowable apply(Action _next) throws Exception { + return Flowable.just(action); } }); } - return Single.just(action); + return Flowable.just(action); } @Override - public Single afterDispatch(Action action) { - return Single.just(action); + public Flowable afterDispatch(Action action) { + return Flowable.just(action); } } From c3b9b69e794d742a24cfc3e30137946eba8c69cf Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:05:33 +0900 Subject: [PATCH 06/20] Use Flowable instead of Single on sample project --- .../generator/StoreClassGenerator.java | 3 +- .../izumin/android/droidux/StoreImpl.java | 9 ++++-- .../example/todomvc/MainActivityHelper.java | 29 ++++++++++-------- .../droidux/example/todomvc/RootStore.java | 4 +-- .../example/todomvc/middleware/Logger.java | 11 ++++--- .../example/todoswithdagger/RootStore.java | 4 +-- .../module/main/MainPresenter.java | 22 +++++++------- .../todoswithundo/MainActivityHelper.java | 30 +++++++++++-------- .../example/todoswithundo/RootStore.java | 4 +-- .../todoswithundo/middleware/Logger.java | 9 +++--- 10 files changed, 68 insertions(+), 57 deletions(-) diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java index e06f51a..8773574 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/generator/StoreClassGenerator.java @@ -26,6 +26,7 @@ import info.izumin.android.droidux.processor.model.StoreImplModel; import info.izumin.android.droidux.processor.model.StoreMethodModel; import info.izumin.android.droidux.processor.model.StoreModel; +import io.reactivex.Flowable; import io.reactivex.Single; import static info.izumin.android.droidux.processor.util.PoetUtils.getOverrideAnnotation; @@ -157,7 +158,7 @@ private MethodSpec createDispatchMethodSpec() { return MethodSpec.methodBuilder(StoreModel.DISPATCH_METHOD_NAME) .addAnnotation(getOverrideAnnotation()) .addModifiers(Modifier.PUBLIC) - .returns(ParameterizedTypeName.get(ClassName.get(Single.class), ClassName.get(Action.class))) + .returns(ParameterizedTypeName.get(ClassName.get(Flowable.class), ClassName.get(Action.class))) .addParameter(getParameterSpec(Action.class)) .addStatement("return $N.$N($N)", DispatcherModel.VARIABLE_NAME, DispatcherModel.DISPATCH_METHOD_NAME, diff --git a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java index 94252d8..efed5fc 100644 --- a/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java +++ b/droidux/src/main/java/info/izumin/android/droidux/StoreImpl.java @@ -5,7 +5,6 @@ import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; -import io.reactivex.Observable; import io.reactivex.subjects.BehaviorSubject; /** @@ -26,8 +25,12 @@ protected StoreImpl(T state, R reducer) { listeners = new HashSet<>(); } - public Observable observe() { - return subject; + public Flowable observe() { + return observe(BackpressureStrategy.DROP); + } + + public Flowable observe(BackpressureStrategy strategy) { + return subject.toFlowable(strategy); } public T getState() { diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java index 8b98002..4b0a7b8 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java @@ -11,7 +11,10 @@ import info.izumin.android.droidux.example.todomvc.action.ClearCompletedTodoAction; import info.izumin.android.droidux.example.todomvc.action.DeleteTodoAction; import info.izumin.android.droidux.example.todomvc.action.ToggleCompletedTodoAction; +import io.reactivex.BackpressureStrategy; +import io.reactivex.Flowable; import io.reactivex.Single; +import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.SingleSubject; /** @@ -40,7 +43,7 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + .flatMap(s -> store.dispatch(new AddTodoAction(s))) /*TODO: Version up RxAndroid*/ /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { @@ -73,27 +76,27 @@ public boolean onOptionItemSelected(MenuItem item) { } } - private Single observeOnClickBtnAddTodo() { - SingleSubject subject = SingleSubject.create(); - btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString())); - return subject; + private Flowable observeOnClickBtnAddTodo() { + PublishSubject subject = PublishSubject.create(); + btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString())); + return subject.toFlowable(BackpressureStrategy.DROP); } - private Single observeOnClickListItem() { - SingleSubject subject = SingleSubject.create(); - listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id)); - return subject; + private Flowable observeOnClickListItem() { + PublishSubject subject = PublishSubject.create(); + listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id)); + return subject.toFlowable(BackpressureStrategy.DROP); } - private Single observeOnLongClickListItem() { - SingleSubject subject = SingleSubject.create(); + private Flowable observeOnLongClickListItem() { + PublishSubject subject = PublishSubject.create(); listTodo.setOnItemLongClickListener((parent, view, position, id) -> { new AlertDialog.Builder(activity) .setTitle(R.string.dialog_delete_todo_title) .setMessage(activity.getString(R.string.dialog_delete_todo_message, store.todoList().getTodoById((int) id).getText())) .setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> { - subject.onSuccess(id); + subject.onNext(id); }) .setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> { dialog.dismiss(); @@ -101,6 +104,6 @@ private Single observeOnLongClickListItem() { .show(); return true; }); - return subject; + return subject.toFlowable(BackpressureStrategy.DROP); } } diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java index 83c983f..aa20717 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todomvc.entity.TodoList; import info.izumin.android.droidux.example.todomvc.reducer.TodoListReducer; -import io.reactivex.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/29/15. @@ -12,5 +12,5 @@ @Store(TodoListReducer.class) public interface RootStore extends BaseStore { TodoList todoList(); - Observable observeTodoList(); + Flowable observeTodoList(); } diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java index 529d8d6..df866f7 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/middleware/Logger.java @@ -5,8 +5,7 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Middleware; import info.izumin.android.droidux.example.todomvc.RootStore; -import io.reactivex.Single; -import rx.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/4/15. @@ -15,15 +14,15 @@ public class Logger extends Middleware { public static final String TAG = Logger.class.getSimpleName(); @Override - public Single beforeDispatch(Action action) { + public Flowable beforeDispatch(Action action) { Log.d("[prev todo]", getStore().todoList().toString()); Log.d("[" + action.getClass().getSimpleName() + "]", action.toString()); - return Single.just(action); + return Flowable.just(action); } @Override - public Single afterDispatch(Action action) { + public Flowable afterDispatch(Action action) { Log.d("[next todo]", getStore().todoList().toString()); - return Single.just(action); + return Flowable.just(action); } } diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java index 9c105e2..a2ed8e6 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; import info.izumin.android.droidux.example.todoswithdagger.reducer.TodoListReducer; -import io.reactivex.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/29/15. @@ -12,5 +12,5 @@ @Store(TodoListReducer.class) public interface RootStore extends BaseStore { TodoList todoList(); - Observable observeTodoList(); + Flowable observeTodoList(); } diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java index 89cb814..f13fb4f 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java @@ -8,7 +8,7 @@ import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.subjects.SingleSubject; +import io.reactivex.subjects.PublishSubject; /** * Created by izumin on 11/5/15. @@ -19,9 +19,9 @@ public class MainPresenter { private final MainView view; private final RootStore store; - private final SingleSubject clickAddTodoSubject = SingleSubject.create(); - private final SingleSubject clickItemSubject = SingleSubject.create(); - private final SingleSubject longClickItemSubject = SingleSubject.create(); + private final PublishSubject clickAddTodoSubject = PublishSubject.create(); + private final PublishSubject clickItemSubject = PublishSubject.create(); + private final PublishSubject longClickItemSubject = PublishSubject.create(); private CompositeDisposable compositeDisposable; @@ -35,21 +35,21 @@ void onStart() { compositeDisposable.add(clickAddTodoSubject .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + .flatMap(s -> store.dispatch(new AddTodoAction(s)).toObservable()) /*TODO: Version up RxAndroid*/ /*.subscribeOn(AndroidSchedulers.mainThread())*/ - .flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toMaybe()) + .flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toObservable()) .subscribe(_a -> { view.clearNewTodoText(); view.showToast(R.string.toast_add_todo); })); compositeDisposable.add(clickItemSubject - .flatMap(id -> store.dispatch(new ToggleCompletedTodoAction(id.intValue()))) + .flatMap(id -> store.dispatch(new ToggleCompletedTodoAction(id.intValue())).toObservable()) .subscribe()); compositeDisposable.add(longClickItemSubject - .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) + .flatMap(id -> store.dispatch(new DeleteTodoAction(id)).toObservable()) /*TODO: Version up RxAndroid*/ /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> view.showToast(R.string.toast_delete_todo))); @@ -60,15 +60,15 @@ void onStop() { } void onClickBtnAddTodo(String text) { - clickAddTodoSubject.onSuccess(text); + clickAddTodoSubject.onNext(text); } void onClickListItem(long id) { - clickItemSubject.onSuccess(id); + clickItemSubject.onNext(id); } void onLongClickListItem(long id) { - longClickItemSubject.onSuccess(id); + longClickItemSubject.onNext(id); } void clearCompletedTodo() { diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java index f20aaf7..9138479 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java @@ -14,7 +14,11 @@ import info.izumin.android.droidux.example.todoswithundo.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithundo.action.ToggleCompletedTodoAction; import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer; +import io.reactivex.BackpressureStrategy; +import io.reactivex.Flowable; +import io.reactivex.Observable; import io.reactivex.Single; +import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.SingleSubject; /** @@ -43,7 +47,7 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) - .flatMap(s -> store.dispatch(new AddTodoAction(s)).toMaybe()) + .flatMap(s -> store.dispatch(new AddTodoAction(s))) /*TODO: Version up RxAndroid*/ /*.subscribeOn(AndroidSchedulers.mainThread())*/ .subscribe(action -> { @@ -82,27 +86,27 @@ public boolean onOptionItemSelected(MenuItem item) { } } - private io.reactivex.Single observeOnClickBtnAddTodo() { - SingleSubject subject = SingleSubject.create(); - btnAddTodo.setOnClickListener(v -> subject.onSuccess(editNewTodo.getText().toString())); - return subject; + private Flowable observeOnClickBtnAddTodo() { + PublishSubject subject = PublishSubject.create(); + btnAddTodo.setOnClickListener(v -> subject.onNext(editNewTodo.getText().toString())); + return subject.toFlowable(BackpressureStrategy.DROP); } - private io.reactivex.Single observeOnClickListItem() { - SingleSubject subject = SingleSubject.create(); - listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onSuccess(id)); - return subject; + private Flowable observeOnClickListItem() { + PublishSubject subject = PublishSubject.create(); + listTodo.setOnItemClickListener((parent, view, position, id) -> subject.onNext(id)); + return subject.toFlowable(BackpressureStrategy.DROP); } - private Single observeOnLongClickListItem() { - SingleSubject subject = SingleSubject.create(); + private Flowable observeOnLongClickListItem() { + PublishSubject subject = PublishSubject.create(); listTodo.setOnItemLongClickListener((parent, view, position, id) -> { new AlertDialog.Builder(activity) .setTitle(R.string.dialog_delete_todo_title) .setMessage(activity.getString(R.string.dialog_delete_todo_message, store.todoList().getTodoById((int) id).getText())) .setPositiveButton(R.string.dialog_delete_todo_btn_positive, (dialog, which) -> { - subject.onSuccess(id); + subject.onNext(id); }) .setNeutralButton(R.string.dialog_delete_todo_btn_neutral, (dialog, which) -> { dialog.dismiss(); @@ -110,6 +114,6 @@ private Single observeOnLongClickListItem() { .show(); return true; }); - return subject; + return subject.toFlowable(BackpressureStrategy.DROP); } } diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java index 88788ec..9de8a1f 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/RootStore.java @@ -4,7 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todoswithundo.entity.TodoList; import info.izumin.android.droidux.example.todoswithundo.reducer.TodoListReducer; -import io.reactivex.Observable; +import io.reactivex.Flowable; /** * Created by izumin on 11/29/15. @@ -12,5 +12,5 @@ @Store(TodoListReducer.class) public interface RootStore extends BaseStore { TodoList todoList(); - Observable observeTodoList(); + Flowable observeTodoList(); } diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java index 9d5d160..739f710 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/middleware/Logger.java @@ -5,6 +5,7 @@ import info.izumin.android.droidux.Action; import info.izumin.android.droidux.Middleware; import info.izumin.android.droidux.example.todoswithundo.RootStore; +import io.reactivex.Flowable; import io.reactivex.Single; /** @@ -15,15 +16,15 @@ public class Logger extends Middleware { @Override - public Single beforeDispatch(Action action) { + public Flowable beforeDispatch(Action action) { Log.d("[prev todo]", getStore().todoList().toString()); Log.d("[" + action.getClass().getSimpleName() + "]", action.toString()); - return Single.just(action); + return Flowable.just(action); } @Override - public Single afterDispatch(Action action) { + public Flowable afterDispatch(Action action) { Log.d("[next todo]", getStore().todoList().toString()); - return Single.just(action); + return Flowable.just(action); } } From fcf9d4ad34d1ee8e361b7dee7794976fea0e9d27 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:07:05 +0900 Subject: [PATCH 07/20] Fix DispatcherTest --- .../izumin/android/droidux/DispatcherTest.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy b/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy index ff78565..85513b0 100644 --- a/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy +++ b/droidux/src/test/groovy/info/izumin/android/droidux/DispatcherTest.groovy @@ -1,7 +1,7 @@ package info.izumin.android.droidux -import io.reactivex.Single -import spock.lang.Specification; +import io.reactivex.Flowable +import spock.lang.Specification /** * Created by izumin on 11/24/15. @@ -34,10 +34,10 @@ class DispatcherTest extends Specification { dispatcher.dispatch(action).subscribe() then: - 1 * middleware1.beforeDispatch(action) >> Single.just(action) + 1 * middleware1.beforeDispatch(action) >> Flowable.just(action) then: - 1 * middleware2.beforeDispatch(action) >> Single.just(action) + 1 * middleware2.beforeDispatch(action) >> Flowable.just(action) then: 1 * store1.dispatch(action) @@ -46,9 +46,9 @@ class DispatcherTest extends Specification { 1 * store2.dispatch(action) then: - 1 * middleware2.afterDispatch(action) >> Single.just(action) + 1 * middleware2.afterDispatch(action) >> Flowable.just(action) then: - 1 * middleware1.afterDispatch(action) >> Single.just(action) + 1 * middleware1.afterDispatch(action) >> Flowable.just(action) } } From acbfef4adfa1707b55d580834c970e7e3639678c Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:15:54 +0900 Subject: [PATCH 08/20] Fix singleReducerTest --- .../android/droidux/processor/fixture/Source.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index 332a2ee..f04ea55 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -87,11 +87,11 @@ public static class Counter { "import info.izumin.android.droidux.BaseStore;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", - "import io.reactivex.Observable;", + "import io.reactivex.Flowable;", "@Store({CounterReducer.class})", "public interface RootStore extends BaseStore {", " Counter counter();", - " Observable observeCounter();", + " Flowable observeCounter();", "}" }; @@ -105,9 +105,9 @@ public static class Counter { "import info.izumin.android.droidux.exception.NotInitializedException;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", + "import io.reactivex.Flowable;", "import java.util.ArrayList;", "import java.util.List;", - "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -131,12 +131,12 @@ public static class Counter { " }", "", " @Override", - " public Observable observeCounter() {", + " public Flowable observeCounter() {", " return counterStoreImpl.observe();", " }", "", " @Override", - " public Observable dispatch(Action action) {", + " public Flowable dispatch(Action action) {", " return dispatcher.dispatch(action)", " }", "", From 4163348397178a3a68d4803ebeda44a4a47bdc9c Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:20:22 +0900 Subject: [PATCH 09/20] Fix combinedReducerAndBindableReducer --- .../android/droidux/processor/fixture/Source.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index f04ea55..a609a61 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -421,13 +421,13 @@ public static class CombinedReducerAndBindableReducer { "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.TodoList;", - "import io.reactivex.Observable;", + "import io.reactivex.Flowable;", "@Store({CounterReducer.class, TodoListReducer.class})", "public interface RootStore extends BaseStore, android.databinding.Observable {", " Counter counter();", - " Observable observeCounter();", + " Flowable observeCounter();", " @Bindable TodoList todoList();", - " Observable observeTodoList();", + " Flowable observeTodoList();", "}" }; @@ -444,9 +444,9 @@ public static class CombinedReducerAndBindableReducer { "import info.izumin.android.droidux.processor.fixture.CounterReducer;", "import info.izumin.android.droidux.processor.fixture.TodoList;", "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", + "import io.reactivex.Flowable;", "import java.util.ArrayList;", "import java.util.List;", - "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -478,7 +478,7 @@ public static class CombinedReducerAndBindableReducer { " }", "", " @Override", - " public Observable observeCounter() {", + " public Flowable observeCounter() {", " return counterStoreImpl.observe();", " }", "", @@ -488,12 +488,12 @@ public static class CombinedReducerAndBindableReducer { " }", "", " @Override", - " public Observable observeTodoList() {", + " public Flowable observeTodoList() {", " return todoListStoreImpl.observe();", " }", "", " @Override", - " public Observable dispatch(Action action) {", + " public Flowable dispatch(Action action) {", " return dispatcher.dispatch(action)", " }", "", From b4de3ba58ac57f8a9fadaf8c52450975cd412d42 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:21:49 +0900 Subject: [PATCH 10/20] Fix singleReducerBindable --- .../android/droidux/processor/fixture/Source.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index a609a61..dd6ab2d 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -184,11 +184,11 @@ public static class BindableCounter { "import info.izumin.android.droidux.BaseStore;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", - "import io.reactivex.Observable;", + "import io.reactivex.Flowable;", "@Store({CounterReducer.class})", "public interface RootStore extends BaseStore, android.databinding.Observable {", " @Bindable Counter counter();", - " Observable observeCounter();", + " Flowable observeCounter();", "}" }; @@ -203,9 +203,9 @@ public static class BindableCounter { "import info.izumin.android.droidux.exception.NotInitializedException;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.CounterReducer;", + "import io.reactivex.Flowable;", "import java.util.ArrayList;", "import java.util.List;", - "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -235,12 +235,12 @@ public static class BindableCounter { " }", "", " @Override", - " public Observable observeCounter() {", + " public Flowable observeCounter() {", " return counterStoreImpl.observe();", " }", "", " @Override", - " public Observable dispatch(Action action) {", + " public Flowable dispatch(Action action) {", " return dispatcher.dispatch(action)", " }", "", From f631b9237c98f7b9da3fa38ca12a294d29b82d7b Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:23:54 +0900 Subject: [PATCH 11/20] combinedTwoReducers --- .../android/droidux/processor/fixture/Source.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index dd6ab2d..064c5bc 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -291,13 +291,13 @@ public static class CombinedTwoReducers { "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", "import info.izumin.android.droidux.processor.fixture.Counter;", "import info.izumin.android.droidux.processor.fixture.TodoList;", - "import rx.Observable;", + "import io.reactivex.Flowable;", "@Store({CounterReducer.class, TodoListReducer.class})", "public interface RootStore extends BaseStore {", " Counter counter();", - " Observable observeCounter();", + " Flowable observeCounter();", " TodoList todoList();", - " Observable observeTodoList();", + " Flowable observeTodoList();", "}" }; @@ -313,9 +313,9 @@ public static class CombinedTwoReducers { "import info.izumin.android.droidux.processor.fixture.CounterReducer;", "import info.izumin.android.droidux.processor.fixture.TodoList;", "import info.izumin.android.droidux.processor.fixture.TodoListReducer;", + "import io.reactivex.Flowable;", "import java.util.ArrayList;", "import java.util.List;", - "import io.reactivex.Observable;", "", "public final class DroiduxRootStore extends BaseObservable implements RootStore {", " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", @@ -341,7 +341,7 @@ public static class CombinedTwoReducers { " }", "", " @Override", - " public Observable observeCounter() {", + " public Flowable observeCounter() {", " return counterStoreImpl.observe();", " }", "", @@ -351,12 +351,12 @@ public static class CombinedTwoReducers { " }", "", " @Override", - " public Observable observeTodoList() {", + " public Flowable observeTodoList() {", " return todoListStoreImpl.observe();", " }", "", " @Override", - " public Observable dispatch(Action action) {", + " public Flowable dispatch(Action action) {", " return dispatcher.dispatch(action)", " }", "", From 17d82c070f33fcf8f8d7186a1181d0a1593af3c9 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:30:51 +0900 Subject: [PATCH 12/20] Fix ThunkMiddlewareTest --- .../droidux/thunk/ThunkMiddlewareTest.groovy | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/middlewares/droidux-thunk/src/test/groovy/info/izumin/android/droidux/thunk/ThunkMiddlewareTest.groovy b/middlewares/droidux-thunk/src/test/groovy/info/izumin/android/droidux/thunk/ThunkMiddlewareTest.groovy index dcbf391..65e439d 100644 --- a/middlewares/droidux-thunk/src/test/groovy/info/izumin/android/droidux/thunk/ThunkMiddlewareTest.groovy +++ b/middlewares/droidux-thunk/src/test/groovy/info/izumin/android/droidux/thunk/ThunkMiddlewareTest.groovy @@ -4,7 +4,7 @@ import info.izumin.android.droidux.Action import info.izumin.android.droidux.Dispatcher import info.izumin.android.droidux.Middleware import info.izumin.android.droidux.StoreImpl -import rx.Observable +import io.reactivex.Flowable import spock.lang.Specification /** @@ -32,8 +32,8 @@ class ThunkMiddlewareTest extends Specification { action = Mock(Action.class) asyncAction = new AsyncAction() { @Override - Observable call(Dispatcher d) { - d.dispatch(preAction).flatMap({_a -> Observable.just(action) }) as Observable + Flowable call(Dispatcher d) { + d.dispatch(preAction).flatMap({_a -> Flowable.just(action) }) as Flowable } } @@ -51,13 +51,13 @@ class ThunkMiddlewareTest extends Specification { dispatcher.dispatch(asyncAction).subscribe() then: - 1 * middleware1.beforeDispatch(asyncAction) >> Observable.just(asyncAction) + 1 * middleware1.beforeDispatch(asyncAction) >> Flowable.just(asyncAction) then: - 1 * middleware1.beforeDispatch(preAction) >> Observable.just(preAction) + 1 * middleware1.beforeDispatch(preAction) >> Flowable.just(preAction) then: - 1 * middleware2.beforeDispatch(preAction) >> Observable.just(preAction) + 1 * middleware2.beforeDispatch(preAction) >> Flowable.just(preAction) then: 1 * store1.dispatch(preAction) @@ -66,16 +66,16 @@ class ThunkMiddlewareTest extends Specification { 1 * store2.dispatch(preAction) then: - 1 * middleware2.afterDispatch(preAction) >> Observable.just(preAction) + 1 * middleware2.afterDispatch(preAction) >> Flowable.just(preAction) then: - 1 * middleware1.afterDispatch(preAction) >> Observable.just(preAction) + 1 * middleware1.afterDispatch(preAction) >> Flowable.just(preAction) then: - 1 * middleware1.beforeDispatch(action) >> Observable.just(action) + 1 * middleware1.beforeDispatch(action) >> Flowable.just(action) then: - 1 * middleware2.beforeDispatch(action) >> Observable.just(action) + 1 * middleware2.beforeDispatch(action) >> Flowable.just(action) then: 1 * store1.dispatch(action) @@ -84,13 +84,13 @@ class ThunkMiddlewareTest extends Specification { 1 * store2.dispatch(action) then: - 1 * middleware2.afterDispatch(action) >> Observable.just(action) + 1 * middleware2.afterDispatch(action) >> Flowable.just(action) then: - 1 * middleware1.afterDispatch(action) >> Observable.just(action) + 1 * middleware1.afterDispatch(action) >> Flowable.just(action) then: - 1 * middleware2.beforeDispatch(asyncAction) >> Observable.just(asyncAction) + 1 * middleware2.beforeDispatch(asyncAction) >> Flowable.just(asyncAction) then: 1 * store1.dispatch(asyncAction) @@ -99,9 +99,9 @@ class ThunkMiddlewareTest extends Specification { 1 * store2.dispatch(asyncAction) then: - 1 * middleware2.afterDispatch(asyncAction) >> Observable.just(asyncAction) + 1 * middleware2.afterDispatch(asyncAction) >> Flowable.just(asyncAction) then: - 1 * middleware1.afterDispatch(asyncAction) >> Observable.just(asyncAction) + 1 * middleware1.afterDispatch(asyncAction) >> Flowable.just(asyncAction) } } From b96dcc40dde090af6a1f39f71d08d1e10f3fbe57 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 22:46:44 +0900 Subject: [PATCH 13/20] Remove all RxJava1 dependencies --- build.gradle | 3 +-- droidux-processor/build.gradle | 1 - examples/counter/build.gradle | 4 ++-- examples/todomvc/build.gradle | 4 ++-- examples/todos-with-dagger/build.gradle | 4 ++-- examples/todos-with-undo/build.gradle | 4 ++-- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 4dcc636..125ded4 100644 --- a/build.gradle +++ b/build.gradle @@ -44,9 +44,8 @@ ext { databindingBaseLibraryVersion = '1.0' databindingLibraryVersion = '1.0-rc3' supportLibrariesVersion = '23.1.1' - rxJavaVersion = '1.1.0' rxJava2Version = '2.1.8' - rxAndroidVersion = '1.0.1' + rxAndroid2Version = '2.0.1' spockCoreVersion = '1.0-groovy-2.4' cglibVersion = '2.2' } diff --git a/droidux-processor/build.gradle b/droidux-processor/build.gradle index d20a654..49565af 100644 --- a/droidux-processor/build.gradle +++ b/droidux-processor/build.gradle @@ -19,7 +19,6 @@ dependencies { compile 'com.google.auto:auto-common:0.6' compile 'com.google.auto.service:auto-service:1.0-rc2' - compile "io.reactivex:rxjava:${project.rxJavaVersion}" compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" compile "com.android.databinding:baseLibrary:${project.databindingBaseLibraryVersion}" compile fileTree(dir: './libs', includes: ['*.jar']) diff --git a/examples/counter/build.gradle b/examples/counter/build.gradle index 683234e..adfd35b 100644 --- a/examples/counter/build.gradle +++ b/examples/counter/build.gradle @@ -30,8 +30,8 @@ android { } dependencies { - compile "io.reactivex:rxjava:${project.rxJavaVersion}" - compile "io.reactivex:rxandroid:${project.rxAndroidVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" + compile "io.reactivex.rxjava2:rxandroid:${project.rxAndroid2Version}" compile project(':droidux') annotationProcessor project(':droidux-processor') compile project(':middlewares:droidux-thunk') diff --git a/examples/todomvc/build.gradle b/examples/todomvc/build.gradle index fb4bfe5..dc69db4 100644 --- a/examples/todomvc/build.gradle +++ b/examples/todomvc/build.gradle @@ -32,8 +32,8 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile "io.reactivex:rxjava:${project.rxJavaVersion}" - compile "io.reactivex:rxandroid:${project.rxAndroidVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" + compile "io.reactivex.rxjava2:rxandroid:${project.rxAndroid2Version}" compile project(':droidux') annotationProcessor project(':droidux-processor') compile "com.android.support:appcompat-v7:${project.supportLibrariesVersion}" diff --git a/examples/todos-with-dagger/build.gradle b/examples/todos-with-dagger/build.gradle index a1963da..13f48d0 100644 --- a/examples/todos-with-dagger/build.gradle +++ b/examples/todos-with-dagger/build.gradle @@ -37,8 +37,8 @@ configurations.all { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile "io.reactivex:rxjava:${project.rxJavaVersion}" - compile "io.reactivex:rxandroid:${project.rxAndroidVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" + compile "io.reactivex.rxjava2:rxandroid:${project.rxAndroid2Version}" compile project(':droidux') annotationProcessor project(':droidux-processor') compile "com.android.support:appcompat-v7:${project.supportLibrariesVersion}" diff --git a/examples/todos-with-undo/build.gradle b/examples/todos-with-undo/build.gradle index 7e3ffa7..2defb11 100644 --- a/examples/todos-with-undo/build.gradle +++ b/examples/todos-with-undo/build.gradle @@ -32,8 +32,8 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile "io.reactivex:rxjava:${project.rxJavaVersion}" - compile "io.reactivex:rxandroid:${project.rxAndroidVersion}" + compile "io.reactivex.rxjava2:rxjava:${project.rxJava2Version}" + compile "io.reactivex.rxjava2:rxandroid:${project.rxAndroid2Version}" compile project(':droidux') annotationProcessor project(':droidux-processor') compile "com.android.support:appcompat-v7:${project.supportLibrariesVersion}" From f0cab996642b90070a88503052ca4b175331db17 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 23:02:24 +0900 Subject: [PATCH 14/20] Remove RxJava1 dependencies completely --- .../example/todomvc/MainActivityHelper.java | 7 +++---- .../example/todomvc/entity/TodoList.java | 7 ++++--- .../todomvc/reducer/TodoListReducer.java | 21 +++++++++++-------- .../todoswithdagger/entity/TodoList.java | 6 +++--- .../module/main/MainPresenter.java | 7 +++---- .../reducer/TodoListReducer.java | 20 ++++++++++-------- .../todoswithundo/MainActivityHelper.java | 7 +++---- .../todoswithundo/entity/TodoList.java | 6 +++--- .../reducer/TodoListReducer.java | 20 ++++++++++-------- 9 files changed, 53 insertions(+), 48 deletions(-) diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java index 4b0a7b8..bb713a7 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/MainActivityHelper.java @@ -14,6 +14,7 @@ import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import io.reactivex.Single; +import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.SingleSubject; @@ -44,8 +45,7 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) .flatMap(s -> store.dispatch(new AddTodoAction(s))) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(action -> { editNewTodo.setText(""); Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show(); @@ -57,8 +57,7 @@ public void onCreate() { observeOnLongClickListItem() .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(action -> { Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show(); }); diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/entity/TodoList.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/entity/TodoList.java index 675a315..4274d38 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/entity/TodoList.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/entity/TodoList.java @@ -4,7 +4,8 @@ import java.util.List; -import rx.Observable; +import io.reactivex.Observable; + /** * Created by izumin on 11/4/15. @@ -23,8 +24,8 @@ public List getTodoList() { } public Todo getTodoById(int id) { - return Observable.from(getTodoList()) - .filter(todo -> id == todo.getId()).toBlocking().first(); + return Observable.fromIterable(getTodoList()) + .filter(todo -> id == todo.getId()).blockingFirst(); } @Override diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java index a08080a..020eb4d 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java @@ -9,7 +9,8 @@ import info.izumin.android.droidux.example.todomvc.action.DeleteTodoAction; import info.izumin.android.droidux.example.todomvc.action.ToggleCompletedTodoAction; import info.izumin.android.droidux.example.todomvc.entity.TodoList; -import rx.Observable; +import io.reactivex.Observable; + /** * Created by izumin on 11/4/15. @@ -21,38 +22,40 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList onAddedTodo(TodoList state, AddTodoAction action) { List list = state.getTodoList(); - int id = Observable.from(list) + int id = Observable.fromIterable(list) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) .onErrorReturn(throwable -> new TodoList.Todo(0, "")) - .toBlocking().last().getId(); + .toObservable() + .blockingLast() + .getId(); list.add(new TodoList.Todo(id + 1, action.getText())); return new TodoList(list); } @Dispatchable(ToggleCompletedTodoAction.class) public TodoList onCompletedTodo(TodoList state, ToggleCompletedTodoAction action) { - return new TodoList(Observable.from(state.getTodoList()) + return new TodoList(Observable.fromIterable(state.getTodoList()) .map(todo -> { if (todo.getId() == action.getId()) { return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted()); } return todo; }) - .toList().toBlocking().single() + .toList().blockingGet() ); } @Dispatchable(ClearCompletedTodoAction.class) public TodoList onClearCompletedTodo(TodoList state, ClearCompletedTodoAction action) { - return new TodoList(Observable.from(state.getTodoList()) - .filter(todo -> !todo.isCompleted()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state.getTodoList()) + .filter(todo -> !todo.isCompleted()).toList().blockingGet() ); } @Dispatchable(DeleteTodoAction.class) public TodoList onDeletedTodo(TodoList state, DeleteTodoAction action) { - return new TodoList(Observable.from(state.getTodoList()) - .filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state.getTodoList()) + .filter(todo -> todo.getId() != action.getId()).toList().blockingGet() ); } } diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/entity/TodoList.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/entity/TodoList.java index 01fbc51..b08a411 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/entity/TodoList.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/entity/TodoList.java @@ -6,7 +6,7 @@ import java.util.List; import info.izumin.android.droidux.UndoableState; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/4/15. @@ -22,8 +22,8 @@ public TodoList(List list) { } public Todo getTodoById(int id) { - return Observable.from(this) - .filter(todo -> id == todo.getId()).toBlocking().first(); + return Observable.fromIterable(this) + .filter(todo -> id == todo.getId()).blockingFirst(); } @Override diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java index f13fb4f..3963c43 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/module/main/MainPresenter.java @@ -7,6 +7,7 @@ import info.izumin.android.droidux.example.todoswithdagger.action.ClearNewTodoTextAction; import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction; +import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.subjects.PublishSubject; @@ -36,8 +37,7 @@ void onStart() { compositeDisposable.add(clickAddTodoSubject .filter(s -> !s.isEmpty()) .flatMap(s -> store.dispatch(new AddTodoAction(s)).toObservable()) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .flatMap(_a -> store.dispatch(new ClearNewTodoTextAction()).toObservable()) .subscribe(_a -> { view.clearNewTodoText(); @@ -50,8 +50,7 @@ void onStart() { compositeDisposable.add(longClickItemSubject .flatMap(id -> store.dispatch(new DeleteTodoAction(id)).toObservable()) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(action -> view.showToast(R.string.toast_delete_todo))); } diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java index a1d69c4..7e19fd6 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java @@ -7,7 +7,7 @@ import info.izumin.android.droidux.example.todoswithdagger.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithdagger.action.ToggleCompletedTodoAction; import info.izumin.android.droidux.example.todoswithdagger.entity.TodoList; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/4/15. @@ -18,10 +18,12 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList add(TodoList state, AddTodoAction action) { - int id = Observable.from(state) + int id = Observable.fromIterable(state) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) .onErrorReturn(throwable -> new TodoList.Todo(0, "")) - .toBlocking().last().getId(); + .toObservable() + .blockingLast() + .getId(); TodoList newState = new TodoList(state); newState.add(new TodoList.Todo(id + 1, action.getText())); return newState; @@ -29,28 +31,28 @@ public TodoList add(TodoList state, AddTodoAction action) { @Dispatchable(ToggleCompletedTodoAction.class) public TodoList complete(TodoList state, ToggleCompletedTodoAction action) { - return new TodoList(Observable.from(state) + return new TodoList(Observable.fromIterable(state) .map(todo -> { if (todo.getId() == action.getId()) { return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted()); } return todo; }) - .toList().toBlocking().single() + .toList().blockingGet() ); } @Dispatchable(ClearCompletedTodoAction.class) public TodoList clear(TodoList state) { - return new TodoList(Observable.from(state) - .filter(todo -> !todo.isCompleted()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state) + .filter(todo -> !todo.isCompleted()).toList().blockingGet() ); } @Dispatchable(DeleteTodoAction.class) public TodoList delete(TodoList state, DeleteTodoAction action) { - return new TodoList(Observable.from(state) - .filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state) + .filter(todo -> todo.getId() != action.getId()).toList().blockingGet() ); } } diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java index 9138479..59d0ac7 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/MainActivityHelper.java @@ -18,6 +18,7 @@ import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.Single; +import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.subjects.PublishSubject; import io.reactivex.subjects.SingleSubject; @@ -48,8 +49,7 @@ public void onCreate() { observeOnClickBtnAddTodo() .filter(s -> !s.isEmpty()) .flatMap(s -> store.dispatch(new AddTodoAction(s))) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(action -> { editNewTodo.setText(""); Toast.makeText(activity, R.string.toast_add_todo, Toast.LENGTH_SHORT).show(); @@ -61,8 +61,7 @@ public void onCreate() { observeOnLongClickListItem() .flatMap(id -> store.dispatch(new DeleteTodoAction(id))) - /*TODO: Version up RxAndroid*/ - /*.subscribeOn(AndroidSchedulers.mainThread())*/ + .subscribeOn(AndroidSchedulers.mainThread()) .subscribe(action -> { Toast.makeText(activity, R.string.toast_delete_todo, Toast.LENGTH_SHORT).show(); }); diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/entity/TodoList.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/entity/TodoList.java index 0726fb5..0968c9b 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/entity/TodoList.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/entity/TodoList.java @@ -6,7 +6,7 @@ import java.util.List; import info.izumin.android.droidux.UndoableState; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/4/15. @@ -22,8 +22,8 @@ public TodoList(List list) { } public Todo getTodoById(int id) { - return Observable.from(this) - .filter(todo -> id == todo.getId()).toBlocking().first(); + return Observable.fromIterable(this) + .filter(todo -> id == todo.getId()).blockingFirst(); } @Override diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java index 6502d1a..9e1218e 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java @@ -8,7 +8,7 @@ import info.izumin.android.droidux.example.todoswithundo.action.DeleteTodoAction; import info.izumin.android.droidux.example.todoswithundo.action.ToggleCompletedTodoAction; import info.izumin.android.droidux.example.todoswithundo.entity.TodoList; -import rx.Observable; +import io.reactivex.Observable; /** * Created by izumin on 11/4/15. @@ -20,10 +20,12 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList onAddedTodo(TodoList state, AddTodoAction action) { - int id = Observable.from(state) + int id = Observable.fromIterable(state) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) .onErrorReturn(throwable -> new TodoList.Todo(0, "")) - .toBlocking().last().getId(); + .toObservable() + .blockingLast() + .getId(); TodoList newState = new TodoList(state); newState.add(new TodoList.Todo(id + 1, action.getText())); return newState; @@ -31,28 +33,28 @@ public TodoList onAddedTodo(TodoList state, AddTodoAction action) { @Dispatchable(ToggleCompletedTodoAction.class) public TodoList onCompletedTodo(TodoList state, ToggleCompletedTodoAction action) { - return new TodoList(Observable.from(state) + return new TodoList(Observable.fromIterable(state) .map(todo -> { if (todo.getId() == action.getId()) { return new TodoList.Todo(todo.getId(), todo.getText(), !todo.isCompleted()); } return todo; }) - .toList().toBlocking().single() + .toList().blockingGet() ); } @Dispatchable(ClearCompletedTodoAction.class) public TodoList onClearCompletedTodo(TodoList state, ClearCompletedTodoAction action) { - return new TodoList(Observable.from(state) - .filter(todo -> !todo.isCompleted()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state) + .filter(todo -> !todo.isCompleted()).toList().blockingGet() ); } @Dispatchable(DeleteTodoAction.class) public TodoList onDeletedTodo(TodoList state, DeleteTodoAction action) { - return new TodoList(Observable.from(state) - .filter(todo -> todo.getId() != action.getId()).toList().toBlocking().single() + return new TodoList(Observable.fromIterable(state) + .filter(todo -> todo.getId() != action.getId()).toList().blockingGet() ); } } From a5626a8cfd9e434c8de76efca14a573b32831cbc Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 23:27:22 +0900 Subject: [PATCH 15/20] Fix TodoMVC sample --- .../droidux/example/todomvc/reducer/TodoListReducer.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java index 020eb4d..5284604 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/reducer/TodoListReducer.java @@ -22,11 +22,13 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList onAddedTodo(TodoList state, AddTodoAction action) { List list = state.getTodoList(); + if (list.isEmpty()) { + list.add(new TodoList.Todo(0, action.getText())); + return new TodoList(list); + } int id = Observable.fromIterable(list) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) - .onErrorReturn(throwable -> new TodoList.Todo(0, "")) - .toObservable() - .blockingLast() + .blockingGet() .getId(); list.add(new TodoList.Todo(id + 1, action.getText())); return new TodoList(list); From d8010adbeb56d08b7d1a96fbd1b2299a90b08919 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 23:40:55 +0900 Subject: [PATCH 16/20] Fix Todo-with-dagger --- .../example/todoswithdagger/reducer/TodoListReducer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java index 7e19fd6..a4d3017 100644 --- a/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java +++ b/examples/todos-with-dagger/src/main/java/info/izumin/android/droidux/example/todoswithdagger/reducer/TodoListReducer.java @@ -18,11 +18,15 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList add(TodoList state, AddTodoAction action) { + if (state.isEmpty()) { + TodoList newState = new TodoList(state); + newState.add(new TodoList.Todo(0, action.getText())); + return newState; + } int id = Observable.fromIterable(state) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) .onErrorReturn(throwable -> new TodoList.Todo(0, "")) - .toObservable() - .blockingLast() + .blockingGet() .getId(); TodoList newState = new TodoList(state); newState.add(new TodoList.Todo(id + 1, action.getText())); From 2c36b49a21b62ab3efe9aadedeee2c2bea8b3bc6 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 23:43:14 +0900 Subject: [PATCH 17/20] Fix Todo-with-undo --- .../example/todoswithundo/reducer/TodoListReducer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java index 9e1218e..f9545c8 100644 --- a/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java +++ b/examples/todos-with-undo/src/main/java/info/izumin/android/droidux/example/todoswithundo/reducer/TodoListReducer.java @@ -20,6 +20,11 @@ public class TodoListReducer { @Dispatchable(AddTodoAction.class) public TodoList onAddedTodo(TodoList state, AddTodoAction action) { + if (state.isEmpty()) { + TodoList newState = new TodoList(state); + newState.add(new TodoList.Todo(0, action.getText())); + return newState; + } int id = Observable.fromIterable(state) .reduce((todo, todo2) -> (todo.getId() < todo2.getId()) ? todo2 : todo) .onErrorReturn(throwable -> new TodoList.Todo(0, "")) From 9cc9089eb644f2880b95518396cd4c9d9152cc7d Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Wed, 3 Jan 2018 20:43:06 +0900 Subject: [PATCH 18/20] Modify README.md --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b83d111..57ef2c8 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Droidux is influenced by [Three principles][three-principles] of Redux. Features of Droidux are following: -* All mutations can be observed via rx.Observable from [RxJava][rxjava] +* All mutations can be observed via Flowable from [RxJava][rxjava] * All mutations are automatically notified to views via [Data Binding][databinding] ### Data flow @@ -37,8 +37,9 @@ Add to your project build.gradle file: apply plugin: 'com.android.application' dependencies { - compile 'io.reactivex:rxjava:1.1.0' compile 'info.izumin.android:droidux:0.6.0' + compile 'io.reactivex.rxjava2:rxjava:2.1.8' + compile 'io.reactivex.rxjava2:rxandroid:2.0.1' annotationProcessor 'info.izumin.android:droidux-processor:0.6.0' } ``` @@ -113,7 +114,7 @@ public class CounterReducer { @Store(CounterReducer.class) public interface CounterStore extends BaseStore { Counter getCounter(); - Observable observeCounter(); + Flowable observeCounter(); } /** @@ -131,8 +132,8 @@ public class ClearCountAction implements Action {} // and it should register a reducer instance and an initial state. // // Its APIs in this example are following: -// - rx.Observable dispatch(Action action) -// - rx.Observable observeCounter() +// - Flowable dispatch(Action action) +// - Flowable observeCounter() // - Counter getCounter() CounterStore store = DroiduxCounterStore.builder() .setReducer(new CounterReducer(), new Counter(0)) @@ -195,9 +196,9 @@ Layout file is following: @Store({CounterReducer.class, TodoListReducer.class}) class RootStore extends BaseStore { Counter getCounter(); - Observable observeCounter(); + Flowable observeCounter(); TodoList getTodoList(); - Observable observeTodoList(); + Flowable observeTodoList(); } @@ -216,16 +217,16 @@ store.dispatch(new AddTodoAction("new task")).subscribe(); // Counter: 1, Todo: ```java class Logger extends Middleware { @Override - public Observable beforeDispatch(Action action) { + public Flowable beforeDispatch(Action action) { Log.d("[prev counter]", String.valueOf(getStore().count())); Log.d("[action]", action.getClass().getSimpleName()); - return Observable.just(action); + return Flowable.just(action); } @Override - public Observable afterDispatch(Action action) { + public Flowable afterDispatch(Action action) { Log.d("[next counter]", String.valueOf(getStore().count())); - return Observable.just(action); + return Flowable.just(action); } } @@ -285,7 +286,7 @@ class TodoListReducer { @Store(TodoListReducer.class) public interface TodoListStore { TodoList todoList(); - Observable observeTodoList(); + Flowable observeTodoList(); } class AddTodoAction implements Action { @@ -329,7 +330,7 @@ class FetchTodoListAction implements AsyncAction { this.client = client; } - public Observable call(Dispatcher dispatcher) { + public Flowable call(Dispatcher dispatcher) { return dispatcher.dispatch(new DoingFetchAction()) .flatMap(_action -> client.fetch()) .map(todoList -> { From 5e28f4a56e41a5a63b6957f86362d9403d9e51e9 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Wed, 3 Jan 2018 23:56:16 +0900 Subject: [PATCH 19/20] Gen observe method with BackpressureStrategy param --- .../processor/model/StoreMethodModel.java | 24 ++++++++++++++++++- .../droidux/example/todomvc/RootStore.java | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java index e74b973..5bb7819 100644 --- a/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java +++ b/droidux-processor/src/main/java/info/izumin/android/droidux/processor/model/StoreMethodModel.java @@ -17,6 +17,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; +import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; /** @@ -29,16 +30,19 @@ enum Kind { DISPATCH, GETTER, OBSERVE, + OBSERVE_WITH_BPS, UNKNOWN } private static final Class OBSERVE_METHOD_CLASS = Flowable.class; + private static final Class BACKPRESSURE_STRATEGY_PARAM_CLASS = BackpressureStrategy.class; private final ExecutableElement element; private final StoreModel storeModel; private final Kind kind; private final DeclaredType returnType; private boolean isBindable = false; + private String bpsParamName = ""; public StoreMethodModel(ExecutableElement element, StoreModel storeModel) { this.element = element; @@ -61,7 +65,14 @@ public TypeName apply(StoreImplModel input) { kind = Kind.DISPATCH; } else if (MoreTypes.isTypeOf(OBSERVE_METHOD_CLASS, returnType.asElement().asType()) && states.contains(ClassName.get(returnType.getTypeArguments().get(0)))) { - kind = Kind.OBSERVE; + if (element.getParameters() != null + && !element.getParameters().isEmpty() + && MoreTypes.isTypeOf(BACKPRESSURE_STRATEGY_PARAM_CLASS, element.getParameters().get(0).asType())) { + bpsParamName = element.getParameters().get(0).getSimpleName().toString(); + kind = Kind.OBSERVE_WITH_BPS; + } else { + kind = Kind.OBSERVE; + } } else { kind = Kind.UNKNOWN; } @@ -99,6 +110,17 @@ public boolean apply(StoreImplModel input) { }) .get(0).getVariableName(), StoreImplModel.STATE_OBSERVE_METHOD_NAME).build(); + case OBSERVE_WITH_BPS: + return CodeBlock.builder().addStatement("return $N.$N(" + bpsParamName + ")", + FluentIterable.from(storeModel.getStoreImplModels()) + .filter(new Predicate() { + @Override + public boolean apply(StoreImplModel input) { + return ClassName.get(returnType.getTypeArguments().get(0)).equals(input.getState()); + } + }) + .get(0).getVariableName(), + StoreImplModel.STATE_OBSERVE_METHOD_NAME).build(); case DISPATCH: return CodeBlock.builder() .addStatement("return $N.$N($N)", DispatcherModel.VARIABLE_NAME, diff --git a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java index aa20717..a0a52b9 100644 --- a/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java +++ b/examples/todomvc/src/main/java/info/izumin/android/droidux/example/todomvc/RootStore.java @@ -4,6 +4,7 @@ import info.izumin.android.droidux.annotation.Store; import info.izumin.android.droidux.example.todomvc.entity.TodoList; import info.izumin.android.droidux.example.todomvc.reducer.TodoListReducer; +import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; /** @@ -13,4 +14,5 @@ public interface RootStore extends BaseStore { TodoList todoList(); Flowable observeTodoList(); + Flowable observeTodoList(BackpressureStrategy strategy); } From 5b3a91edb2485d5d6ddfc96c9c9876c2d40573fc Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Thu, 4 Jan 2018 00:06:43 +0900 Subject: [PATCH 20/20] Add test for support BackpressureStrategy specification --- .../processor/DroiduxProcessorTest.java | 10 ++ .../droidux/processor/fixture/Source.java | 105 ++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/DroiduxProcessorTest.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/DroiduxProcessorTest.java index 1e6f5e4..fe6b2bd 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/DroiduxProcessorTest.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/DroiduxProcessorTest.java @@ -7,6 +7,7 @@ import javax.tools.JavaFileObject; import info.izumin.android.droidux.processor.fixture.Source; +import io.reactivex.BackpressureStrategy; import static com.google.common.truth.Truth.assert_; import static com.google.testing.compile.JavaFileObjects.forSourceLines; @@ -39,6 +40,15 @@ public void singleReducer() { ); } + @Test + public void singleReducer_with_BackpressureStrategySpecification() { + assertJavaSource( + forSourceLines("RootStore", Source.CounterWithBackpressureStrategy.TARGET), + forSourceLines("DroiduxRootStore_CounterStoreImpl", Source.StoreImpl.COUNTER), + forSourceLines("DroiduxRootStore", Source.CounterWithBackpressureStrategy.GENERATED_STORE) + ); + } + @Test public void singleReducerBindable() { assertJavaSource( diff --git a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java index 064c5bc..ff7c301 100644 --- a/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java +++ b/droidux-processor/src/test/java/info/izumin/android/droidux/processor/fixture/Source.java @@ -175,6 +175,111 @@ public static class Counter { }; } + public static class CounterWithBackpressureStrategy { + public static final String[] TARGET = { + "package info.izumin.android.droidux.sample;", + "import info.izumin.android.droidux.annotation.Store;", + "import info.izumin.android.droidux.Action;", + "import info.izumin.android.droidux.BaseStore;", + "import info.izumin.android.droidux.processor.fixture.Counter;", + "import info.izumin.android.droidux.processor.fixture.CounterReducer;", + "import io.reactivex.BackpressureStrategy;", + "import io.reactivex.Flowable;", + "@Store({CounterReducer.class})", + "public interface RootStore extends BaseStore {", + " Counter counter();", + " Flowable observeCounter();", + " Flowable observeCounter(BackpressureStrategy strategy);", + "}" + }; + + public static final String[] GENERATED_STORE = { + "package info.izumin.android.droidux.sample;", + "", + "import android.databinding.BaseObservable;", + "import info.izumin.android.droidux.Action;", + "import info.izumin.android.droidux.Dispatcher;", + "import info.izumin.android.droidux.Middleware;", + "import info.izumin.android.droidux.exception.NotInitializedException;", + "import info.izumin.android.droidux.processor.fixture.Counter;", + "import info.izumin.android.droidux.processor.fixture.CounterReducer;", + "import io.reactivex.BackpressureStrategy;", + "import io.reactivex.Flowable;", + "import java.util.ArrayList;", + "import java.util.List;", + "", + "public final class DroiduxRootStore extends BaseObservable implements RootStore {", + " private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;", + " private final Dispatcher dispatcher;", + "", + " protected DroiduxRootStore(final Builder builder) {", + " counterStoreImpl= new DroiduxRootStore_CounterStoreImpl(builder.counter, builder.counterReducer);", + " dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl);", + " for (Middleware middleware : builder.middlewares) {", + " middleware.onAttach(this, dispatcher);", + " }", + " }", + "", + " public static Builder builder() {", + " return new Builder();", + " }", + "", + " @Override", + " public Counter counter() {", + " return counterStoreImpl.getState();", + " }", + "", + " @Override", + " public Flowable observeCounter() {", + " return counterStoreImpl.observe();", + " }", + "", + "", + " @Override", + " public Flowable observeCounter(BackpressureStrategy strategy) {", + " return counterStoreImpl.observe(strategy);", + " }", + "", + " @Override", + " public Flowable dispatch(Action action) {", + " return dispatcher.dispatch(action)", + " }", + "", + " public static final class Builder {", + " private final List middlewares;", + " private CounterReducer counterReducer;", + " private Counter counter;", + "", + " private Builder() {", + " middlewares = new ArrayList<>();", + " }", + "", + " public Builder addMiddleware(Middleware middleware) {", + " middlewares.add(middleware);", + " return this;", + " }", + "", + " public Builder setReducer(CounterReducer counterReducer) {", + " this.counterReducer = counterReducer;", + " return this;", + " }", + "", + " public Builder setReducer(CounterReducer counterReducer, Counter counter) {", + " this.counter = counter;", + " return setReducer(counterReducer);", + " }", + "", + " public DroiduxRootStore build() {", + " if (counterReducer == null) {", + " throw new NotInitializedException(\"CounterReducer has not been initialized.\");", + " }", + " return new DroiduxRootStore(this);", + " }", + " }", + "}" + }; + } + public static class BindableCounter { public static final String[] TARGET = { "package info.izumin.android.droidux.sample;",