From 5bb9d15e2745fe3eded4e6b4ee32653c97ea6979 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 17 Mar 2019 10:07:28 +0100 Subject: [PATCH] Refactored tagEdit reducer to take advantage of redux-actions --- src/short-urls/reducers/shortUrlCreation.js | 4 +-- src/short-urls/reducers/shortUrlDeletion.js | 4 +-- src/tags/reducers/tagEdit.js | 38 +++++++-------------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/short-urls/reducers/shortUrlCreation.js b/src/short-urls/reducers/shortUrlCreation.js index 6188feff..b98cc1d6 100644 --- a/src/short-urls/reducers/shortUrlCreation.js +++ b/src/short-urls/reducers/shortUrlCreation.js @@ -1,12 +1,12 @@ import PropTypes from 'prop-types'; import { createAction, handleActions } from 'redux-actions'; -/* eslint-disable padding-line-between-statements, newline-after-var */ +/* eslint-disable padding-line-between-statements */ export const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START'; export const CREATE_SHORT_URL_ERROR = 'shlink/createShortUrl/CREATE_SHORT_URL_ERROR'; export const CREATE_SHORT_URL = 'shlink/createShortUrl/CREATE_SHORT_URL'; export const RESET_CREATE_SHORT_URL = 'shlink/createShortUrl/RESET_CREATE_SHORT_URL'; -/* eslint-enable padding-line-between-statements, newline-after-var */ +/* eslint-enable padding-line-between-statements */ export const createShortUrlResultType = PropTypes.shape({ result: PropTypes.shape({ diff --git a/src/short-urls/reducers/shortUrlDeletion.js b/src/short-urls/reducers/shortUrlDeletion.js index 74980bc7..3b13241f 100644 --- a/src/short-urls/reducers/shortUrlDeletion.js +++ b/src/short-urls/reducers/shortUrlDeletion.js @@ -1,13 +1,13 @@ import { createAction, handleActions } from 'redux-actions'; import PropTypes from 'prop-types'; -/* eslint-disable padding-line-between-statements, newline-after-var */ +/* eslint-disable padding-line-between-statements */ export const DELETE_SHORT_URL_START = 'shlink/deleteShortUrl/DELETE_SHORT_URL_START'; export const DELETE_SHORT_URL_ERROR = 'shlink/deleteShortUrl/DELETE_SHORT_URL_ERROR'; export const DELETE_SHORT_URL = 'shlink/deleteShortUrl/DELETE_SHORT_URL'; export const RESET_DELETE_SHORT_URL = 'shlink/deleteShortUrl/RESET_DELETE_SHORT_URL'; export const SHORT_URL_DELETED = 'shlink/deleteShortUrl/SHORT_URL_DELETED'; -/* eslint-enable padding-line-between-statements, newline-after-var */ +/* eslint-enable padding-line-between-statements */ export const shortUrlDeletionType = PropTypes.shape({ shortCode: PropTypes.string.isRequired, diff --git a/src/tags/reducers/tagEdit.js b/src/tags/reducers/tagEdit.js index 950e95db..393d7660 100644 --- a/src/tags/reducers/tagEdit.js +++ b/src/tags/reducers/tagEdit.js @@ -1,10 +1,11 @@ import { pick } from 'ramda'; +import { handleActions } from 'redux-actions'; -/* eslint-disable padding-line-between-statements, newline-after-var */ +/* eslint-disable padding-line-between-statements */ export const EDIT_TAG_START = 'shlink/editTag/EDIT_TAG_START'; export const EDIT_TAG_ERROR = 'shlink/editTag/EDIT_TAG_ERROR'; export const EDIT_TAG = 'shlink/editTag/EDIT_TAG'; -/* eslint-enable padding-line-between-statements, newline-after-var */ +/* eslint-enable padding-line-between-statements */ export const TAG_EDITED = 'shlink/editTag/TAG_EDITED'; @@ -15,30 +16,15 @@ const defaultState = { error: false, }; -export default function reducer(state = defaultState, action) { - switch (action.type) { - case EDIT_TAG_START: - return { - ...state, - editing: true, - error: false, - }; - case EDIT_TAG_ERROR: - return { - ...state, - editing: false, - error: true, - }; - case EDIT_TAG: - return { - ...pick([ 'oldName', 'newName' ], action), - editing: false, - error: false, - }; - default: - return state; - } -} +export default handleActions({ + [EDIT_TAG_START]: (state) => ({ ...state, editing: true, error: false }), + [EDIT_TAG_ERROR]: (state) => ({ ...state, editing: false, error: true }), + [EDIT_TAG]: (state, action) => ({ + ...pick([ 'oldName', 'newName' ], action), + editing: false, + error: false, + }), +}, defaultState); export const editTag = (buildShlinkApiClient, colorGenerator) => (oldName, newName, color) => async ( dispatch,