-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstore.js
65 lines (53 loc) · 1.65 KB
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { syncHistory, routeReducer } from 'react-router-redux'
import { ui, books, notification, categories, authors } from './reducers'
import thunk from 'redux-thunk';
import { applyMiddleware, createStore, combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form';
import createHistory from 'history/lib/createHashHistory'
// Opt-out of persistent state, not recommended.
// http://rackt.org/history/stable/HashHistoryCaveats.html
export const history = createHistory({
queryKey: false
});
const combineReducers2 = o => {
return (state={}, action) => {
const mapped = Object.keys(o).map(k => (
{
key: k,
slice: o[k](state[k], action)
}
))
const reduced = mapped.reduce((s, x)=>{
s[x['key']]=x['slice']
return s
}, {})
return reduced;
}
}
const combineReducers3 = o => (state={}, action) => Object.keys(o).map(k => [
k, o[k](state[k], action)
]).reduce((s, x) => Object.assign(s, {
[x[0]]: x[1]
}), {})
//const reducer = combineReducers3(Object.assign({}, {
const reducer = combineReducers(Object.assign({}, {
books,
notification,
ui,
categories,
authors,
}, {
routing: routeReducer
}, {
form: formReducer
})
)
const reduxRouterMiddleware = syncHistory(history)
const logStateMiddleware = ({dispatch, getState}) => next => action => {
console.log(action.type, getState())
next(action)
}
const store = createStore(reducer, applyMiddleware(
thunk, reduxRouterMiddleware
));
export default store