All files / core reducer.js

12.5% Statements 2/16
0% Branches 0/9
0% Functions 0/1
12.5% Lines 2/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 342x         2x                                                        
const initialState = {
  results: { },
  currentSearch: { q: '*' },
  previousSearch: {},
};
const reducer = (state = initialState, action) => {
  if (typeof action === 'undefined' || typeof action.type === 'undefined') {
    return state;
  }
  switch (action.type) {
    case 'ADD': {
      const copy = state;
      copy.results = action.results;
      return { ...copy };
    }
    case 'APPEND': {
      const copy = state;
      copy.results.response.products = state.results.response.products
        .concat(action.results.response.products);
      copy.results.response.start = action.results.response.start;
      return { ...copy };
    }
    case 'UPDATE_QUERY': {
      const copy = state;
      copy.currentSearch.q = action.query;
      return copy;
    }
    default:
      return state;
  }
};
 
export default reducer;