{"size": 1737, "ext": "js", "max_stars_repo_path": "src/client/reducers/gameReducer.js", "max_stars_repo_name": "mccl0ud/turtle-racer", "max_stars_repo_stars_event_min_datetime": "2018-10-08T21:29:08.000Z", "max_stars_repo_stars_event_max_datetime": "2018-10-09T06:44:57.000Z", "max_issues_repo_path": "src/client/reducers/gameReducer.js", "max_issues_repo_name": "mccl0ud/turtle-racer", "max_issues_repo_issues_event_min_datetime": "2018-10-10T21:48:06.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-11T19:28:20.000Z", "max_forks_repo_path": "src/client/reducers/gameReducer.js", "max_forks_repo_name": "mccl0ud/turtle-racer", "max_forks_repo_forks_event_min_datetime": "2018-10-08T21:29:13.000Z", "max_forks_repo_forks_event_max_datetime": "2018-10-08T21:47:45.000Z"}
{"max_stars_count": 2, "max_issues_count": 2, "max_forks_count": 4, "avg_line_length": 32.1666666667, "max_line_length": 66, "alphanum_fraction": 0.6902705815}
import * as types from '../constants/actionTypes';

const initialState = {
  // store prompt in state to pass down as a prop
  prompt: '',
  // text contained in the Input component
  userInput: '',
  // string of valid words typed by the user
  validWords: '',
  // string of valid input of the current word typed by the user
  validInput: '',
  // string of invalid input of the current word typed by the user
  invalidInput: '',
  // current character to be typed by the user
  currChar: '',
  // next character to be typed by the user
  nextChar: '',
  // remaining words in the passage
  remainingWords: '',
};

const gameReducer = (state = initialState, action) => {
  switch (action.type) {
    // add the prompt retrieved from the database to the state
    case types.ADD_PROMPT:
      return { 
        prompt: action.payload,
        // initalize remainingWords with the prompt
        remainingWords: action.payload 
      };
    // send input to the server and reset the input field
    case types.SEND_AND_UPDATE_INPUT_TO_SERVER:
      // emit to socket and update state
    case types.GET_USER_INPUT:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_VALID_WORDS:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_VALID_INPUT:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_INVALID_INPUT:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_CURR_CHAR:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_NEXT_CHAR:
      // emit to socket and update state
    case types.SEND_AND_UPDATE_REMAINING_WORDS:
      // emit to socket and update state
    default:
      return state;
  }
};

export default gameReducer;
