Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. @AutoReducer
  2. public abstract class TodoReducer implements Reducer<List<TodoItem>> {
  3.  
  4. @AutoReducer.Action(TodoActions.ADD_ITEM)
  5. List<TodoItem> addItem(List<TodoItem> items, TodoItem item) {
  6. return TreePVector.from(items)
  7. .plus(item);
  8. }
  9.  
  10. @AutoReducer.Action(TodoActions.CHANGE_STATE)
  11. List<TodoItem> changeState(List<TodoItem> items, long id, boolean isChecked) {
  12. for (int i = 0; i < items.size(); i++) {
  13. TodoItem todoItem = items.get(i);
  14. if (todoItem.id == id) {
  15. TodoItem changed = new TodoItem(id, todoItem.text, isChecked);
  16. return TreePVector.from(items)
  17. .with(i, changed);
  18. }
  19. }
  20. return items;
  21. }
  22.  
  23. public static TodoReducer create() {
  24. return new TodoReducerImpl();
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement