{"size": 764, "ext": "js", "max_stars_repo_path": "src/modules/searchInput/reducers.js", "max_stars_repo_name": "char0n/apiary-switch", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/modules/searchInput/reducers.js", "max_issues_repo_name": "char0n/apiary-switch", "max_issues_repo_issues_event_min_datetime": "2017-06-11T16:59:51.000Z", "max_issues_repo_issues_event_max_datetime": "2017-06-12T16:27:37.000Z", "max_forks_repo_path": "src/modules/searchInput/reducers.js", "max_forks_repo_name": "char0n/apiary-switch", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 17.7674418605, "max_line_length": 83, "alphanum_fraction": 0.664921466}
import { handleActions } from 'redux-actions';

import * as actions from './actions';

/**
 * Initial state
 */

const initialState = {
  searchQueries: [
    'search query 1',
    'search query 2',
  ],
  query: '',
};


/**
 * Case reducers
 */

const filterSuggestions = (state, action) => ({ ...state, query: action.payload });

const rememberSearchQuery = (state, action) => {
  const isQueryEmpty = action.payload.trim() === '';

  if (isQueryEmpty) { return state }

  const searchQueries = state.searchQueries.concat(action.payload);

  return { ...state, searchQueries };
};


/**
 * Root reducer
 */

export default handleActions({
  [actions.filterSuggestions]: filterSuggestions,
  [actions.rememberSearchQuery]: rememberSearchQuery,
}, initialState);
