<commit_before>
'use strict';

import Immutable from 'immutable';

import {
  STOP_TIMER,
  TIMER_STARTED,
  TIMER_UPDATED,
  TIMER_FINISHED,
  TIMER_MAX_VALUE_CHANGED
} from '../actions/timer';

import { CHALLENGE_START } from '../actions/challenge';

const timerDefaultValue = 60 * 1000;

const initialState = Immutable.Map({
  isTimerFinished: false,
  timerMaxValue: timerDefaultValue.toString(),
  timerMaxValueLoaded: timerDefaultValue,
  timeLeft: timerDefaultValue,
  timerStart: 0
});

export default function timer (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state.set('timerMaxValueLoaded', state.get('timerMaxValue'));
    case STOP_TIMER:
      return state
        .set('isTimerFinished', true)
        .set('timeLeft', 0);
    case TIMER_STARTED:
      return state
        .set('isTimerFinished', false)
        .set('timeLeft', timerDefaultValue)
        .set('timerStart', action.startTime);
    case TIMER_UPDATED:
      return state
        .set('timeLeft', parseInt(state.get('timerMaxValueLoaded'), 10) - (action.timeNow - state.get('timerStart')));<commit_msg>timerMaxValue reflects most recent user input time<commit_after>
'use strict';

import Immutable from 'immutable';

import {
  STOP_TIMER,
  TIMER_STARTED,
  TIMER_UPDATED,
  TIMER_FINISHED,
  TIMER_MAX_VALUE_CHANGED
} from '../actions/timer';

import { CHALLENGE_START } from '../actions/challenge';

const timerDefaultValue = 60 * 1000;

const initialState = Immutable.Map({
  isTimerFinished: false,
  timerMaxValue: timerDefaultValue,
  timerMaxValueLoaded: timerDefaultValue,
  timeLeft: timerDefaultValue,
  timerStart: 0
});

export default function timer (state = initialState, action) {
  switch (action.type) {
    case CHALLENGE_START:
      return state.set('timerMaxValueLoaded', state.get('timerMaxValue'));
    case STOP_TIMER:
      return state
        .set('isTimerFinished', true)
        .set('timeLeft', 0);
    case TIMER_STARTED:
      return state
        .set('isTimerFinished', false)
        .set('timeLeft', timerDefaultValue)
        .set('timerStart', action.startTime);
    case TIMER_UPDATED:
      return state
        .set('timeLeft', parseInt(state.get('timerMaxValueLoaded'), 10) - (action.timeNow - state.get('timerStart')));
{'fraction_non_alphanumeric': 0.11705831157528286, 'fraction_numerical': 0.008703220191470844, 'mean_word_length': 3.9334763948497855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7476341', 'n_tokens_mistral': 759, 'n_tokens_neox': 722, 'n_words': 159}