Skip to content

Commit

Permalink
Fix Todo-with-undo
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak3125 committed Jan 2, 2018
1 parent d8010ad commit 2c36b49
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""))
Expand Down

0 comments on commit 2c36b49

Please sign in to comment.