about summary refs log tree commit diff stats
path: root/js/seed/src/update.js
blob: 2f6c13bc435a2e9d1a7894b1ae2e46d0b453cfee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// update.js
// Pure update function

/**
 * @param {object} state - Current state
 * @param {object} action - { type, payload }
 * @returns {object} new state
 */
export function update(state, action) {
  switch (action.type) {
    case 'UPDATE_QUERY':
      return { ...state, query: action.payload, error: null };
    case 'FETCH_START':
      return { ...state, loading: true, error: null, pokemon: null };
    case 'FETCH_SUCCESS':
      return { ...state, loading: false, error: null, pokemon: action.payload };
    case 'FETCH_ERROR':
      return { ...state, loading: false, error: action.payload, pokemon: null };
    default:
      return state;
  }
}