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 34 | 2x 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;
|