diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-28 15:54:41 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-28 15:54:41 +0200 |
| commit | aa5638a1c31ce56d59696580f33733dcf0d7764c (patch) | |
| tree | c2d1bd0e480b9bae113ce9af706927c5b7c55952 /client/store.js | |
| parent | a72ecc91db39ac5a2d60aefc6d767da457500dde (diff) | |
refactor frontend, add threshold slider
Diffstat (limited to 'client/store.js')
| -rw-r--r-- | client/store.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/client/store.js b/client/store.js new file mode 100644 index 0000000..c5f5555 --- /dev/null +++ b/client/store.js @@ -0,0 +1,61 @@ +import { applyMiddleware, compose, combineReducers, createStore } from 'redux' +import { connectRouter, routerMiddleware } from 'connected-react-router' +import { createBrowserHistory } from 'history' +import thunk from 'redux-thunk' +import * as types from './types' + +const initialState = () => ({ + api: null, +}) + +export default function apiReducer(state = initialState(), action) { + // console.log(action.type, action) + switch (action.type) { + case types.api.loading: + return { + ...state, + [action.tag]: { loading: true }, + } + + case types.api.loaded: + return { + ...state, + [action.tag]: action.data, + } + + case types.api.error: + return { + ...state, + [action.tag]: { error: action.err }, + } + + default: + return state + } +} + +const rootReducer = combineReducers({ + api: apiReducer, +}) + +function configureStore(initialState = {}, history) { + const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose + + const store = createStore( + connectRouter(history)(rootReducer), // new root reducer with router state + initialState, + composeEnhancers( + applyMiddleware( + thunk, + routerMiddleware(history) + ), + ), + ) + + return store +} + +const history = createBrowserHistory() +const store = configureStore({}, history) + +export { store, history } |
