Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

droidux-thunk #20

Merged
merged 8 commits into from
Nov 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ private MethodSpec createConstructor() {

final String middlewareFiledName = "middleware";
return builder
.beginControlFlow("for ($T $N : $N.$N)", Middleware.class, middlewareFiledName,
BuilderModel.VARIABLE_NAME, StoreModel.MIDDLEWARES_FIELD_NAME)
.addStatement("$N.$N(this)",
middlewareFiledName, StoreModel.ATTACH_MIDDLEWARE_METHOD_NAME)
.endControlFlow()
.addStatement("$N = new $N($N.$N, $N)",
DispatcherModel.VARIABLE_NAME, DispatcherModel.CLASS_NAME,
BuilderModel.VARIABLE_NAME, BuilderModel.MIDDLEWARES_VARIABLE_NAME,
Expand All @@ -94,6 +89,11 @@ public String apply(StoreImplModel input) {
return input.getVariableName();
}
}).join(Joiner.on(", ")))
.beginControlFlow("for ($T $N : $N.$N)", Middleware.class, middlewareFiledName,
BuilderModel.VARIABLE_NAME, StoreModel.MIDDLEWARES_FIELD_NAME)
.addStatement("$N.$N(this, $N)", middlewareFiledName,
StoreModel.ATTACH_MIDDLEWARE_METHOD_NAME, DispatcherModel.VARIABLE_NAME)
.endControlFlow()
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public static class Counter {
"",
" protected DroiduxRootStore(Builder builder) {",
" counterStoreImpl= new DroiduxRootStore_CounterStoreImpl(builder.counter, builder.counterReducer);",
" dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl);",
" for (Middleware middleware : builder.middlewares) {",
" middleware.onAttach(this)",
" middleware.onAttach(this, dispatcher);",
" }",
" dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl);",
" }",
"",
" public Counter counter() {",
Expand Down Expand Up @@ -219,10 +219,10 @@ public static class CombinedTwoReducers {
" protected DroiduxRootStore(Builder builder) {",
" counterStoreImpl= new DroiduxRootStore_CounterStoreImpl(builder.counter, builder.counterReducer);",
" todoListStoreImpl= new DroiduxRootStore_TodoListStoreImpl(builder.todoList, builder.todoListReducer);",
" dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl, todoListStoreImpl);",
" for (Middleware middleware : builder.middlewares) {",
" middleware.onAttach(this)",
" middleware.onAttach(this, dispatcher);",
" }",
" dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl, todoListStoreImpl);",
" }",
"",
" public Counter counter() {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class AddTodoItemAction extends Action {
public class AddTodoItemAction implements Action {
public static final String TAG = AddTodoItemAction.class.getSimpleName();

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class ClearCountAction extends Action {
public class ClearCountAction implements Action {
public static final String TAG = ClearCountAction.class.getSimpleName();

public ClearCountAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class CompleteTodoItemAction extends Action {
public class CompleteTodoItemAction implements Action {
public static final String TAG = CompleteTodoItemAction.class.getSimpleName();

private final int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class IncrementCountAction extends Action {
public class IncrementCountAction implements Action {
public static final String TAG = IncrementCountAction.class.getSimpleName();

private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class InitializeCountAction extends Action {
public class InitializeCountAction implements Action {
public static final String TAG = InitializeCountAction.class.getSimpleName();

private final int value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by izumin on 11/2/15.
*/
public class SquareCountAction extends Action {
public class SquareCountAction implements Action {
public static final String TAG = SquareCountAction.class.getSimpleName();

public SquareCountAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
/**
* Created by izumin on 11/2/15.
*/
public class Action {
public static final String TAG = Action.class.getSimpleName();
public interface Action {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ public abstract class Middleware<S> {
public static final String TAG = Middleware.class.getSimpleName();

private S store;
private Dispatcher dispatcher;

public void onAttach(S store) {
public void onAttach(S store, Dispatcher dispatcher) {
this.store = store;
this.dispatcher = dispatcher;
}

public S getStore() {
protected S getStore() {
return store;
}

protected Dispatcher getDispatcher() {
return dispatcher;
}

public abstract Observable<Action> beforeDispatch(Action action);
public abstract Observable<Action> afterDispatch(Action action);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Created by izumin on 11/24/15.
*/
public class HistoryAction extends Action {
public class HistoryAction implements Action {
public static final String TAG = HistoryAction.class.getSimpleName();

enum Kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/4/15.
*/
public class AddTodoAction extends Action {
public class AddTodoAction implements Action {
public static final String TAG = AddTodoAction.class.getSimpleName();

private final String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/**
* Created by izumin on 11/5/15.
*/
public class ClearCompletedTodoAction extends Action {
public class ClearCompletedTodoAction implements Action {
public static final String TAG = ClearCompletedTodoAction.class.getSimpleName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/5/15.
*/
public class DeleteTodoAction extends Action {
public class DeleteTodoAction implements Action {
public static final String TAG = DeleteTodoAction.class.getSimpleName();

private final long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/5/15.
*/
public class ToggleCompletedTodoAction extends Action {
public class ToggleCompletedTodoAction implements Action {
public static final String TAG = ToggleCompletedTodoAction.class.getSimpleName();

private final int id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/4/15.
*/
public class AddTodoAction extends Action {
public class AddTodoAction implements Action {
public static final String TAG = AddTodoAction.class.getSimpleName();

private final String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
/**
* Created by izumin on 11/5/15.
*/
public class ClearCompletedTodoAction extends Action {
public class ClearCompletedTodoAction implements Action {
public static final String TAG = ClearCompletedTodoAction.class.getSimpleName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/5/15.
*/
public class DeleteTodoAction extends Action {
public class DeleteTodoAction implements Action {
public static final String TAG = DeleteTodoAction.class.getSimpleName();

private final long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Created by izumin on 11/5/15.
*/
public class ToggleCompletedTodoAction extends Action {
public class ToggleCompletedTodoAction implements Action {
public static final String TAG = ToggleCompletedTodoAction.class.getSimpleName();

private final int id;
Expand Down
1 change: 1 addition & 0 deletions middlewares/droidux-thunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions middlewares/droidux-thunk/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
apply plugin: 'groovyx.grooid.groovy-android'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
provided 'io.reactivex:rxjava:1.0.15'
provided project(':droidux')

testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'cglib:cglib-nodep:2.2'
}

publish {
userOrg = 'izumin5210'
groupId = 'info.izumin.android'
artifactId = 'droidux-thunk'
version = '0.1.0'
description = 'Thunk middleware for Droidux.'
website = 'https://github.com/izumin5210/Droidux'
}
17 changes: 17 additions & 0 deletions middlewares/droidux-thunk/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package info.izumin.android.droidux.thunk;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
11 changes: 11 additions & 0 deletions middlewares/droidux-thunk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.izumin.android.droidux.thunk">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package info.izumin.android.droidux.thunk;

import info.izumin.android.droidux.Action;
import rx.Observable;

/**
* Created by izumin on 11/29/15.
*/
public interface AsyncAction extends Action {
Observable<Action> call();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package info.izumin.android.droidux.thunk;

import info.izumin.android.droidux.Action;
import info.izumin.android.droidux.Middleware;
import rx.Observable;
import rx.functions.Func1;

/**
* Created by izumin on 11/29/15.
*/
public class ThunkMiddleware extends Middleware {
public static final String TAG = ThunkMiddleware.class.getSimpleName();

@Override
public Observable<Action> beforeDispatch(final Action action) {
if (action instanceof AsyncAction) {
return ((AsyncAction) action).call()
.flatMap(new Func1<Action, Observable<Action>>() {
@Override
public Observable<Action> call(Action next) {
return getDispatcher().dispatch(next);
}
})
.flatMap(new Func1<Action, Observable<Action>>() {
@Override
public Observable<Action> call(Action _next) {
return Observable.just(action);
}
});
}
return Observable.just(action);
}

@Override
public Observable<Action> afterDispatch(Action action) {
return Observable.just(action);
}
}
3 changes: 3 additions & 0 deletions middlewares/droidux-thunk/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">DroiduxThunk</string>
</resources>
Loading