{"size": 1894, "ext": "js", "max_stars_repo_path": "src/reducers/tasks.js", "max_stars_repo_name": "r0bs/reduxdo", "max_stars_repo_stars_event_min_datetime": "2018-01-26T03:53:10.000Z", "max_stars_repo_stars_event_max_datetime": "2018-01-26T03:53:10.000Z", "max_issues_repo_path": "src/reducers/tasks.js", "max_issues_repo_name": "r0bs/reduxdo", "max_issues_repo_issues_event_min_datetime": "2017-05-19T14:42:29.000Z", "max_issues_repo_issues_event_max_datetime": "2017-05-30T08:35:04.000Z", "max_forks_repo_path": "src/reducers/tasks.js", "max_forks_repo_name": "r0bs/reduxdo", "max_forks_repo_forks_event_min_datetime": "2020-06-12T13:40:25.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-12T13:40:25.000Z"}
{"max_stars_count": 1, "max_issues_count": 32, "max_forks_count": 1, "avg_line_length": 21.2808988764, "max_line_length": 63, "alphanum_fraction": 0.5570221753}
import {
  ADD_TASK, 
  TOGGLE_TASK, 
  RECEIVE_TASKS, 
  PROCESS_TASK_CREATION_RESPONSE, 
  PROCESS_TASK_UPDATE_RESPONSE,
  CHANGE_TASK,
  CLEAR_FINISHED_TASKS
 } from '../actions/tasks'
 import { LOGGED_OUT } from '../actions/google'
 import { SET_DEFAULT_LIST } from '../actions/tasklists'

const task = (state, action) => {
  switch (action.type) {
    case ADD_TASK:
      return {
        ...state,
        ...action
      }
    case CHANGE_TASK:
      if (state.id !== action.id) {
          return state
        }
      return {
        ...state,
        ...action
      }
    case PROCESS_TASK_CREATION_RESPONSE:
      if (state.id !== action.tempId) {
        return state
      }
      return {
          ...state,
          id: action.permanentId,
          syncInProgress: false
        }
    case PROCESS_TASK_UPDATE_RESPONSE:
      if (state.id !== action.id) {
        return state
      }
      return {
        ...state,
        ...action,
        syncInProgress: false
      }
    case TOGGLE_TASK:
      if (state.id !== action.id) {
        return state
      }
      return {
        ...state,
        completed: !state.completed
      }
    default:
      return state
  }
}

const tasks = (state = [], action) => {
  switch (action.type) {
    case ADD_TASK:
      return [
        ...state,
        task(undefined, action)
      ]
    case LOGGED_OUT:
    case SET_DEFAULT_LIST:
      return []
    case PROCESS_TASK_CREATION_RESPONSE:
    case PROCESS_TASK_UPDATE_RESPONSE:
    case TOGGLE_TASK:
    case CHANGE_TASK:
      return state.map(t =>
        task(t, action)
      )
    case CLEAR_FINISHED_TASKS:
      return state.filter(task => task.status !== "completed");
    case RECEIVE_TASKS:
      const tasks = action.tasks ? action.tasks : [];
      return [
        ...state,
        ...tasks
      ]
    default:
      return state
  }
}

export default tasks