fcc-challenges/drum-machine-react/src/reducers/isMetronomePlayingReducer.js

25 lines
614 B
JavaScript
Raw Normal View History

2020-05-26 07:01:12 -07:00
import { padsArray } from "../Globals";
import { TOGGLEMETRONOME } from "../actions/toggleMetronomeIsPlayingAction.js";
const initMetronomeIsPlaying = () => {
const metronomePlayingStates = {};
padsArray.forEach(key => {
metronomePlayingStates[key + 'metronomeIsPlaying'] = false;
});
return metronomePlayingStates;
};
export default (state, action) => {
if (!state) {
state = initMetronomeIsPlaying();
}
switch (action.type) {
case TOGGLEMETRONOME:
state[action.key + 'metronomeIsPlaying'] = action.metronomeIsPlaying;
return state;
default:
return state;
}
}