From 97fa59123c521ed3f48ecfe00cbe4a78494da090 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 2 Apr 2018 16:46:41 -0700 Subject: [PATCH] Split out userInput reducer --- js/reducers/index.js | 33 +---------------- js/reducers/userInput.js | 36 +++++++++++++++++++ .../{index.test.js => userInput.test.js} | 2 +- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 js/reducers/userInput.js rename js/reducers/{index.test.js => userInput.test.js} (97%) diff --git a/js/reducers/index.js b/js/reducers/index.js index a046464d..6d321502 100644 --- a/js/reducers/index.js +++ b/js/reducers/index.js @@ -2,15 +2,9 @@ import { combineReducers } from "redux"; import { BANDS } from "../constants"; import { SET_BAND_VALUE, - SET_FOCUS, - SET_BAND_FOCUS, - SET_SCRUB_POSITION, SET_EQ_AUTO, SET_EQ_ON, SET_EQ_OFF, - UNSET_FOCUS, - SET_USER_MESSAGE, - UNSET_USER_MESSAGE, SET_AVAILABLE_SKINS, NETWORK_CONNECTED, NETWORK_DISCONNECTED @@ -20,32 +14,7 @@ import playlist from "./playlist"; import windows from "./windows"; import media from "./media"; import display from "./display"; - -const defaultUserInput = { - focus: null, - bandFocused: null, - scrubPosition: 0, - userMessage: null -}; - -export const userInput = (state = defaultUserInput, action) => { - switch (action.type) { - case SET_FOCUS: - return { ...state, focus: action.input, bandFocused: null }; - case SET_BAND_FOCUS: - return { ...state, focus: action.input, bandFocused: action.bandFocused }; - case UNSET_FOCUS: - return { ...state, focus: null, bandFocused: null }; - case SET_SCRUB_POSITION: - return { ...state, scrubPosition: action.position }; - case SET_USER_MESSAGE: - return { ...state, userMessage: action.message }; - case UNSET_USER_MESSAGE: - return { ...state, userMessage: null }; - default: - return state; - } -}; +import userInput from "./userInput"; const defaultSettingsState = { availableSkins: [] diff --git a/js/reducers/userInput.js b/js/reducers/userInput.js new file mode 100644 index 00000000..88d0c28a --- /dev/null +++ b/js/reducers/userInput.js @@ -0,0 +1,36 @@ +import { + SET_FOCUS, + SET_BAND_FOCUS, + SET_SCRUB_POSITION, + UNSET_FOCUS, + SET_USER_MESSAGE, + UNSET_USER_MESSAGE +} from "../actionTypes"; + +const defaultUserInput = { + focus: null, + bandFocused: null, + scrubPosition: 0, + userMessage: null +}; + +export const userInput = (state = defaultUserInput, action) => { + switch (action.type) { + case SET_FOCUS: + return { ...state, focus: action.input, bandFocused: null }; + case SET_BAND_FOCUS: + return { ...state, focus: action.input, bandFocused: action.bandFocused }; + case UNSET_FOCUS: + return { ...state, focus: null, bandFocused: null }; + case SET_SCRUB_POSITION: + return { ...state, scrubPosition: action.position }; + case SET_USER_MESSAGE: + return { ...state, userMessage: action.message }; + case UNSET_USER_MESSAGE: + return { ...state, userMessage: null }; + default: + return state; + } +}; + +export default userInput; diff --git a/js/reducers/index.test.js b/js/reducers/userInput.test.js similarity index 97% rename from js/reducers/index.test.js rename to js/reducers/userInput.test.js index b3c338e9..91af3351 100644 --- a/js/reducers/index.test.js +++ b/js/reducers/userInput.test.js @@ -1,5 +1,5 @@ import { SET_FOCUS, SET_SCRUB_POSITION, UNSET_FOCUS } from "../actionTypes"; -import { userInput } from "./"; +import userInput from "./userInput"; describe("userInput reducer", () => { const state = userInput(undefined, { type: "@@INIT" });