diff options
Diffstat (limited to 'js/seed/src/update.js')
-rw-r--r-- | js/seed/src/update.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/js/seed/src/update.js b/js/seed/src/update.js new file mode 100644 index 0000000..2f6c13b --- /dev/null +++ b/js/seed/src/update.js @@ -0,0 +1,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; + } +} \ No newline at end of file |