summaryrefslogtreecommitdiff
path: root/scraper/client/store.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-02-13 13:58:11 +0100
committerJules Laplace <julescarbon@gmail.com>2019-02-13 13:58:11 +0100
commit392ea8d0ba2fdc713ae156517b0575e8219b9f1c (patch)
treebb29c19f9f0a2d970c39c813130361405fccbe4e /scraper/client/store.js
parentdc7d9cbba842472efb33186e97ee55751e4d50ca (diff)
adding geocode client
Diffstat (limited to 'scraper/client/store.js')
-rw-r--r--scraper/client/store.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/scraper/client/store.js b/scraper/client/store.js
new file mode 100644
index 00000000..08b6e801
--- /dev/null
+++ b/scraper/client/store.js
@@ -0,0 +1,64 @@
+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'
+// import { login } from './util'
+
+// import metadataReducer from './metadata/metadata.reducer'
+
+const initialState = () => ({
+ options: {}
+})
+
+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 }