rsnext/examples/with-redux-thunk/reducers.js
Matt Carlotta ffa4089b18
Update with-redux-thunk example to include HMR (#11816)
* Update with-redux-thunk example to include HMR

* Update README

* Fix clock component

* Fix example component

* Fix README
2020-04-14 18:36:50 -05:00

43 lines
811 B
JavaScript

import { combineReducers } from 'redux'
import * as types from './types'
// COUNTER REDUCER
const counterReducer = (state = 0, { type }) => {
switch (type) {
case types.INCREMENT:
return state + 1
case types.DECREMENT:
return state - 1
case types.RESET:
return 0
default:
return state
}
}
// INITIAL TIMER STATE
const initialTimerState = {
lastUpdate: 0,
light: false,
}
// TIMER REDUCER
const timerReducer = (state = initialTimerState, { type, payload }) => {
switch (type) {
case types.TICK:
return {
lastUpdate: payload.ts,
light: !!payload.light,
}
default:
return state
}
}
// COMBINED REDUCERS
const reducers = {
counter: counterReducer,
timer: timerReducer,
}
export default combineReducers(reducers)