Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. @AutoReducer
  2. public abstract class AppStateReducer implements Reducer<AppState> {
  3.  
  4. //action from TodoReducer
  5. @AutoReducer.Action(TodoActions.ADD_ITEM)
  6. AppState addItem(AppState state, TodoItem item) {
  7. List<TodoItem> items = state.todoItems;
  8. List<TodoItem> updated = TreePVector.from(items)
  9. .plus(item);
  10. return new AppState(updated, state.filter);
  11. }
  12.  
  13. //action from TodoReducer
  14. @AutoReducer.Action(TodoActions.CHANGE_STATE)
  15. AppState changeState(AppState state, long id, boolean isChecked) {
  16. List<TodoItem> items = state.todoItems;
  17. for (int i = 0; i < items.size(); i++) {
  18. TodoItem todoItem = items.get(i);
  19. if (todoItem.id == id) {
  20. TodoItem changed = new TodoItem(id, todoItem.text, isChecked);
  21. PVector<TodoItem> updated = TreePVector.from(items)
  22. .with(i, changed);
  23. return new AppState(updated, state.filter);
  24. }
  25. }
  26. return state;
  27. }
  28.  
  29. //action from FilterReducer
  30. @AutoReducer.Action(TodoActions.SET_FILTER)
  31. AppState setFilter(AppState state, TodoFilter filter) {
  32. return new AppState(state.todoItems, filter);
  33. }
  34.  
  35. public static AppStateReducer create() {
  36. return new AppStateReducerImpl();
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement