Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @AutoReducer
- public abstract class AppStateReducer implements Reducer<AppState> {
- //action from TodoReducer
- @AutoReducer.Action(TodoActions.ADD_ITEM)
- AppState addItem(AppState state, TodoItem item) {
- List<TodoItem> items = state.todoItems;
- List<TodoItem> updated = TreePVector.from(items)
- .plus(item);
- return new AppState(updated, state.filter);
- }
- //action from TodoReducer
- @AutoReducer.Action(TodoActions.CHANGE_STATE)
- AppState changeState(AppState state, long id, boolean isChecked) {
- List<TodoItem> items = state.todoItems;
- for (int i = 0; i < items.size(); i++) {
- TodoItem todoItem = items.get(i);
- if (todoItem.id == id) {
- TodoItem changed = new TodoItem(id, todoItem.text, isChecked);
- PVector<TodoItem> updated = TreePVector.from(items)
- .with(i, changed);
- return new AppState(updated, state.filter);
- }
- }
- return state;
- }
- //action from FilterReducer
- @AutoReducer.Action(TodoActions.SET_FILTER)
- AppState setFilter(AppState state, TodoFilter filter) {
- return new AppState(state.todoItems, filter);
- }
- public static AppStateReducer create() {
- return new AppStateReducerImpl();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement