From 4894ab9035c04966fe342f8a98551715915c9cc7 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 Mar 2019 09:15:58 +0100 Subject: [PATCH] Refactored shortUrlsListParams reducer to takle advantage of redux-actions --- src/short-urls/reducers/shortUrlsListParams.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/short-urls/reducers/shortUrlsListParams.js b/src/short-urls/reducers/shortUrlsListParams.js index ef8de0b6..80f8e42e 100644 --- a/src/short-urls/reducers/shortUrlsListParams.js +++ b/src/short-urls/reducers/shortUrlsListParams.js @@ -1,3 +1,4 @@ +import { createAction, handleActions } from 'redux-actions'; import PropTypes from 'prop-types'; import { LIST_SHORT_URLS } from './shortUrlsList'; @@ -11,15 +12,9 @@ export const shortUrlsListParamsType = PropTypes.shape({ const defaultState = { page: '1' }; -export default function reducer(state = defaultState, action) { - switch (action.type) { - case LIST_SHORT_URLS: - return { ...state, ...action.params }; - case RESET_SHORT_URL_PARAMS: - return defaultState; - default: - return state; - } -} +export default handleActions({ + [LIST_SHORT_URLS]: (state, { params }) => ({ ...state, ...params }), + [RESET_SHORT_URL_PARAMS]: () => defaultState, +}, defaultState); -export const resetShortUrlParams = () => ({ type: RESET_SHORT_URL_PARAMS }); +export const resetShortUrlParams = createAction(RESET_SHORT_URL_PARAMS);