From d8010adbeb56d08b7d1a96fbd1b2299a90b08919 Mon Sep 17 00:00:00 2001 From: Ryo Sakaguchi Date: Tue, 2 Jan 2018 23:40:55 +0900 Subject: [PATCH] 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()));