<commit_before>/* @flow */
import type { FetchingState, Action } from '../types';
import {
  APP_REFRESH,
  LOGOUT,
  LOGIN_SUCCESS,
  ACCOUNT_SWITCH,
  SWITCH_NARROW,
  MESSAGE_FETCH_START,
  MESSAGE_FETCH_COMPLETE,
} from '../actionConstants';
import { NULL_FETCHING, NULL_OBJECT } from '../nullObjects';

const initialState: FetchingState = NULL_OBJECT;

export default (state: FetchingState = initialState, action: Action): FetchingState => {
  switch (action.type) {
    case APP_REFRESH:
    case LOGOUT:
    case LOGIN_SUCCESS:
    case SWITCH_NARROW:
    case ACCOUNT_SWITCH:
      return initialState;

    case MESSAGE_FETCH_START: {
      const key = JSON.stringify(action.narrow);
      const currentValue = state[key] || NULL_FETCHING;

      return {
        ...state,
        [key]: {
          older: action.numBefore > 0 || currentValue.older,
          newer: action.numAfter > 0 || currentValue.newer,
        },
      };
    }

    case MESSAGE_FETCH_COMPLETE: {
      const key = JSON.stringify(action.narrow);
      const currentValue = state[key] || NULL_FETCHING;

      return {
        ...state,
        [key]: {
          older: currentValue.older && action.numBefore === 0,
          newer: currentValue.newer && action.numAfter === 0,
        },
      };
    }

    default:
      return state;
  }
};<commit_msg>flow: Add types to fetchingReducers<commit_after>/* @flow */
import type {
  FetchingState,
  Action,
  MessageFetchStartAction,
  MessageFetchCompleteAction,
} from '../types';
import {
  APP_REFRESH,
  LOGOUT,
  LOGIN_SUCCESS,
  ACCOUNT_SWITCH,
  SWITCH_NARROW,
  MESSAGE_FETCH_START,
  MESSAGE_FETCH_COMPLETE,
} from '../actionConstants';
import { NULL_FETCHING, NULL_OBJECT } from '../nullObjects';

const initialState: FetchingState = NULL_OBJECT;

const messageFetchStart = (
  state: FetchingState,
  action: MessageFetchStartAction,
): FetchingState => {
  const key = JSON.stringify(action.narrow);
  const currentValue = state[key] || NULL_FETCHING;

  return {
    ...state,
    [key]: {
      older: action.numBefore > 0 || currentValue.older,
      newer: action.numAfter > 0 || currentValue.newer,
    },
  };
};

const messageFetchComplete = (
  state: FetchingState,
  action: MessageFetchCompleteAction,
): FetchingState => {
  const key = JSON.stringify(action.narrow);
  const currentValue = state[key] || NULL_FETCHING;

  return {
    ...state,
    [key]: {
      older: currentValue.older && action.numBefore === 0,
      newer: currentValue.newer && action.numAfter === 0,
    },
  };
};

export default (state: FetchingState = initialState, action: Action): FetchingState => {
  switch (action.type) {
    case APP_REFRESH:
    case LOGOUT:
    case LOGIN_SUCCESS:
    case SWITCH_NARROW:
    case ACCOUNT_SWITCH:
      return initialState;

    case MESSAGE_FETCH_START:
      return messageFetchStart(state, action);

    case MESSAGE_FETCH_COMPLETE:
      return messageFetchComplete(state, action);

    default:
      return state;
  }
};
{'fraction_non_alphanumeric': 0.1156530408773679, 'fraction_numerical': 0.0026586905948820204, 'mean_word_length': 3.106412005457026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2334551', 'n_tokens_mistral': 1018, 'n_tokens_neox': 973, 'n_words': 210}